The collision functions will give you the location of the hit on the target object, the normal of the impact, and some other useful data, and the position of the entity after the collision code runs is availble for precise distance measurement... but anythhing other than a straight bounce (i.e. accounting for elasticity, friction, imparted spin, etc) is gonna drive you insane unless you use a physics library like Tokamak or Newton :)
If you are using force based movement, you should be accumalating momentum in a variable every game loop, by updating the momentum variable whenever a force is applied (i.e. while the player holds down the space bar to accelerate, or friction reducing momentum while not accelerating)
I pulled a little code like that to handle players jumping more realistically... imparting an initial force, reducing vertical momentum via gravity, until the player impacts the ground again. Even included a recovery time before they could jump again.
|