I am wondering how extremely basic physics engines work and how I could implement them. lets say I have a player class (like a frame, except it holds the variables for the players), and I would like to add gravity. Could I go something like this

Player p = new Player();

to add gravity to the player? Also I am wondering how easy would it be to do something like this with just gravity, and lets say different friction coefficients (ice, sand, grass, etc)?

Thanks for any help

6 Years
Discussion Span
Last Post by sirlink99

you'd not handle it like that. Rather you'd pass the player and whatever movement input the player has initiated to the physics engine, and get a movement vector as a result.


Simple physics is not hard - store the objects current position and velocity. Use a timer to update them at regular intervals (eg 60 mSec). At each update change the position according to the velocity, and change the velocity according to gravity or friction. For gravity add a fixed downwards increment to the velocity. For friction reduce the velocity by a percentage (depending on how big the coefficient of friction is).
Then add in whatever you need for user input, bouncing off walls/obstacles, collisions etc - but that's where it gets harder!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.