Skip to main content
GameDev.net gamedev.net
🔒 Locked

Why did I try forces?

Started by simnon Apr 8, 2009 at 7:33 PM 3 replies 1.1k views
Original Post
simnon
simnon
Hey Normally I just add velocity to characters position to move characters about, nice simple and works for most of the demos I work on anyway. I decided it was about time I step up my game and use some real physics, Newtonian linear motion at least. So now I have a bot moving,but my bot is trying to approach an object, but because Im just applying a force in the direction of the object, he gets there but is going too fast and goes miles past it. I want to know how to slow down to approach an object, i.e. calculate the force needed to slow down in time. also if I collide with an object how do I get it to jump back a certain distance instantly but not keep going in the direction the force was applied. My game is in 2d :) thanks
Bob Janova
Bob Janova
'Real physics' for walking about on a surface don't really make sense. The actual losses in any sort of real world situation to friction mean that you actively have to keep walking to move.

What Newtonian mechanics simulates is walking on ice with a rocket pack :p and that's not something that you identify easily with.

For collision, you will normally have a function that returns the 'penetration vector' (i.e. which direction the collision happened in and how far into the other object you went). Move the object back by the penetration vector and remove any component of velocity in that direction (i.e. v -= DotProduct(pen.Normalise(), v) ).
simnon
simnon
that penetration code looks promising, definately solves the problem of it over compensating for the collision.

Still unsure how to calculate stopping distance with acceleration involved, but il get a chance tomorrow to sit down and work out the maths behind it hopefully. then we shall see how it goes.

Thanks Janova I appreciate it
stonemetal
stonemetal
Use Vcurrent/A = T this will tell you how long it will take you to stop. Dist = .5 * Vel * T (.5 V being the average velocity over time T since you are stopping) will tell you how far away to begin stopping. This is assuming you have a constant acceleration you can apply. If you are actually looking for the acceleration needed then work it backwards. T = Dist/(.5Vel) then A = Vcurrent/T then F = MA to get force.
simnon
simnon
Thanks a million, thats exactly it.
I Felt kinda stupid in the end, I was way over complicating things.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.