Hello !
Me again with my game engine !
I have an other little problem with my physic engine …
I take some pieces of code of Humper (https://github.com/aloisdeniel/Humper) to make a collision detection and response velocity based, but there is something I can’t solve :
Every update, I have an entity who is velocity is set by that :
Step 1 :
velocity += (acceleration - friction * velocity) * gameTime.ElapsedGameTime.TotalSeconds
Then i calculate collision and if a collision is found, base on the velocity value (wich is the next move of my entity), I get a value wich corresponds to how I must decrease the velocity to avoid the colliion. It looks like this:
Step 2 :
float collisionResponse = FindCollision(myEntity)
(value between 0 and 1)
velocity *= collisionResponse
And finally, I increase my entity position as much as the velocity is, multiplied by the GameTime to smooth the movement and avoid frame drop :
Step 3 :
position += velocity * gameTime.ElapsedGameTime.TotalSeconds
And everything works fine, I have a good value of gravity, I have good and smooth movements, my entity does’nt go through platform, etc …
Except one thing : The FindCollision() return the exact value wich make my entity beside the platform (Step 2), but then in the Step 3, when I add the velocity I must multiply that exact velocity by the elapsed time wich make my velocity slower too soon so my entity slow down before he is next to the platform when he should stop when he has reaches it.
Can you help me ? I know the problem come from the gameTime.ElapsedGameTime.TotalSeconds
but I dont know what to do because if I remove this, my entity go very very too fast.
Thanks !
(Sorry if you did’nt understand something, just tell me and I’ll try to say it in another way (I’m french and I dont like Google Translate :P)(Oh ! A bracket in another bracket !))
Just a sketch of how its made: