Say I have a particle-based physics engine (which I do) that uses lots of particles with a x and y coordinate and velocity. These particles can also have a mass, which means that these particles (with a large enough mass) can attract each other based off their masses. My question is how and where should the program work out the deduction of velocity when moving against a source of gravity, should it check every time a particle gets a new velocity? Or should it check every tick? And also, how would it calculate the deduction of velocity, since I don’t know how it would work with a x and y system
4
As with pretty much any physics simulation, yes you have to calculate everything on every tick. The forces the objects exert on each other are constantly changing (as long as at least one of them is moving), so you can’t really avoid it.
I have no idea what you’re asking specifically about “deduction of velocity”, since the law of gravity works exactly the same way in all direction. It’s also a really simple law to calculate:
F = G * (m1*m2)/r^2
G is a constant, you can probably get away with pretending particles have constant mass, and all that’s left is computing the distance (r) between each pair of particles.
2