Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 02 Apr 2008
Offline Last Active Today, 11:35 AM

#5223871 How to create a circular orbit and an angry bird space like orbit ?

Posted by h4tt3n on 17 April 2015 - 12:09 AM

Believe me deltaweb, it's a much more rewarding experience to actually learn the theory, implement it yourself and see it work than just hack something toghether that only looks real. I should have seen this coming, but I overlooked the angry birds warning. :-)

#5222751 inifinite mass and a jitter problem

Posted by h4tt3n on 12 April 2015 - 09:16 AM

In my opinion the most robust solution is always to only apply some fraction of the total needed impulse, and then iterate through the velocity-part of the constraint until it reaches an equilibrium. 

#5222672 inifinite mass and a jitter problem

Posted by h4tt3n on 11 April 2015 - 05:45 PM

Could it simply be that while the corrective impulse from interacting with brick #1 is exactly enough to counter the finite mass objects perp velocity vector due to movement and gravity, the the impulse caused by interaction with brick #2 does not take this into account and applies the same impulse, resulting in overshoot? I've experienced similar behaviour in some of my innumerable physics experiments.




#5222668 How to create a circular orbit and an angry bird space like orbit ?

Posted by h4tt3n on 11 April 2015 - 05:31 PM

Hi there,


Regarding your first problem, it seems that you have forgotten to apply the velocity perpendicular to the distance vector. Rather it seems like you are applying it in the direction of the attracting body. You do this by making the normalized vector perpendicular: n(x, y) -> n(y, -x) or n(-y, x) depending on wether you want a clockwise or ccw orbit.


Regarding the second problem, angry birds space has very little to do with actual physics, so there can't be a definitive answer. Can you describe the desired effect in a little more detail? (Haven't played the game much).




#5217687 Star System N-Body Simulation Over Long Time Periods

Posted by h4tt3n on 19 March 2015 - 12:29 PM


As long as the simulation is stable, do you really need high accuracy anyway, or is good-enough ok?


"Good-enough" is sufficient, using RK4 integration along with the Barnes-Hut method (for adaptive time steps and less complexity), together allowing me to increase time steps might do the trick. The system tends to become more stable over time and is initially rather chaotic with objects colliding frequently which is where more accuracy would be necessary. Anyway, I will see how that goes and report back later.



RK4 integration is *not* a good choice for n-body simulations, as it is not symplectic and looses energy over time. Instead I would like to recommend David Whysong's symplectic integrators, which can be found here:




If you replace the time-stepping method with Keplers equations of planetary motion, you can accurately compute the position of any celestial body at every conceivable point in time. The drawback is that the equations are limited to two-body interaction.







#5203057 Maths for maths haters

Posted by h4tt3n on 09 January 2015 - 05:20 AM

I'd like to join in and recommend the Khan Academy. 

#5191904 Trajectory of a projectile

Posted by h4tt3n on 09 November 2014 - 01:41 AM

Hello there, you have made a good start. There are two ways of making the tracectory: A so-called analytic one, where the entire trajectory is computed once and for all. And a discrete one, where the projectile moves a little step at a time. For each step, gravity, and perhaps air resistance is added, and when you repeat the steps, the trajectory arc appears. The first method is good if you just want the trajectory and wants to know if you hit or not. The other one is good if you want an actual cannon ball which can bounce off planes, roll around, and be influenced by many different forces.

#5144448 Separating axis Theorem rotation issue

Posted by h4tt3n on 04 April 2014 - 03:30 PM

Hi Aardvajk. I don't actually calculate the distance, since it is not needed. If you want the distance, you need to solve the Pythagorean theorem, which means calling square root. It's getting late here in Europe so I won't go into a lengthy explanation on SAT, but here are some links you might find useful:




#5144278 Separating axis Theorem rotation issue

Posted by h4tt3n on 04 April 2014 - 01:23 AM



It's hard to tell exactly what goes wrong without seeing any code.




It seems like you are doing vector normalization in your code. This isn't necessary and requires a lot of cpu time. Your code should work just fine even if you remove "A.Normalize();"




#5123321 Jittering due to gravity and restitution

Posted by h4tt3n on 13 January 2014 - 11:52 AM

The damping you mention seems wrong. It should always apply force along some axis (along the constraint or normal to intersection), not just remove a fraction of all movement per game loop.


The folowing equation will compute the exact force to make your object align with the floor and come to rest in one step:


correction force = - ( object mass / timestep^2 ) * overlap distance along axis * coefficient - ( object mass / timestep ) * velocity along axis * coefficient


If you are dealing with impulses or velocities then the equation should be:


Correction impulse = - ( object mass / timestep ) * overlap distance along axis * coefficient - velocity along axis * coefficient


The coefficient is just a number between 0 and 1 determining how soft / rigid you want it to behave. Setting the coefficients to 1 will do the job in 1 loop, but may also introduce instability if there are several objects interacting at one time. Setting them between 0.5 and 0.05 should work just fine.




#5118623 Alchemy System, what would make alchemy fun?

Posted by h4tt3n on 21 December 2013 - 02:57 PM

Make it procedural. In ohter words, don't make a number of pre-defined recipies, but instead let the properties of the potion emerge from some pre-defined laws. THis way, not even the game designer himself knows what might happen in every case. This is essentially what makes physics-based games so rewarding, and why they have such a high degree of re-playability. So instead of pre-coding a limited number of recipies, you need to pre-code a limited number of laws or rules from which an infinite number of recipies will emerge.




#5066519 physics force problem

Posted by h4tt3n on 31 May 2013 - 02:51 PM

Hello Lomateron,


I've been working on the exact same problem, but I haven't solved it entirely yet. I've attached a small windows .exe + full source for a small program that propagates forces trough a chain of interconnected particles. It displays far more rigid behaviour than any iterative solver I know of. My method of doing this is very similar to yours, it seems :-)

The only problem is that it's position based, and does not take velocity and acceleration into consideration. Still working on that...




Attached Files

#5012122 billiard/pool balls

Posted by h4tt3n on 18 December 2012 - 12:07 PM

Hi there,

There ae already a few tutorials covering this topic. Here are a few good ones found by googling "pool physics"
I've implemented some of these myself, and it works just fine!



#5005227 Learning Soft Body

Posted by h4tt3n on 29 November 2012 - 02:37 AM

Hi there,

A good place to start is to make a loop of particles connected with springs. Then calculate the rest-area (or "2d volume") using the equation found here, and save it.

For each program loop, calculate the current area and calculate a pressure force, which could look like this:

Fpressure = stiffnes * (area - rest area)

Which is essentially just Hooke's law of elasticity in another form. Then, for each spring, apply a perpendicular pressure force to the particles in each end of the spring.

Integrate with time using your favourite algorithm and repeat. This will make the loop of springs into a neat little water balloon :-)


#4991783 Problem getting correct orbits of planets

Posted by h4tt3n on 19 October 2012 - 08:28 AM

No. F = ma. a = F/m, and the force is defined as F = G m1m2/r^2, so a = F/m = G m/r^2. This is correct. Gravitational acceleration is independent of the "receiving" object's mass.

Yes, you are completely right - But only if you pick the right mass, and I suspect this is where the error lies. Bugs are often harder to find in optimized, compacted code, and that's why I recommend using the original Newtonian force based equation. Also, for the acceleration based calculation to work you need two equations, one for each body. A1 = G m2/r^2 and A2 = G m1/r^2. Otherwise your simulation will not conserve momentum. Sorry if my first post was a bit unclear, I was in a bit of a hurry when writing it.