I am working on the way forces are used in my physics engine and was hoping possible someone could comment if this was general idea (it seems to be from what I gathered from other physics engine/docs)
[color="#000000"][font="Arial"]Apply Gravity to total forces[/font]
[color="#000000"]
[color="#000000"][font="Arial"]Calculate Collisions (using total force + velocity for detecting collision)[/font]
[color="#000000"][font="Arial"]- If there is a friction, add the friction force to total force[/font]
[color="#000000"][font="Arial"]- If there is resting, subtract out the gravity from total force[/font]
[color="#000000"]
[color="#000000"][font="Arial"]Calculate acceleration as “acceleration = total force/mass”[/font]
[color="#000000"][font="Arial"]Calculate velocity as “velocity += acceleration * dt[/font]
[color="#000000"][font="Arial"]Calculate new position as “new position = current position + velocity”[/font]
[color="#000000"]
[color="#000000"][font="Arial"]Set total forces to zero, set acceleration to zero.
Edit: corrected my acceleration formula
[/font]
Calculating and applying forces
I think you want acceleration to be calculated using total force/mass, but apart from that everything else looks fine.
You almost got it. The below scheme is simpe, effective and widely used. It's called the symplectic Euler integration algorithm.
calculate forces
acceleration = force / mass
velocity += acceleration * dt
position += velocity * dt
reset forces and start all over
calculate forces
acceleration = force / mass
velocity += acceleration * dt
position += velocity * dt
reset forces and start all over
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement