Original Post
I've been mulling over this for a while now and i cant seem to get my head around it. Confusion has arisen over how you elegantly combine physics against the world and the controlling of the FPS player. I have a physics object of which the physics manager can hold many. The physics object has a m_Velocity 3D vector that is used to determine the next position of the physics object.
- At the start of the frame the game input code removes the velocity it added to the physics object from the last frame and adds on the new velocity based on what keys are down for the current frame. The reason for the removal is so the velocity doesn't accumulate over the course of many frames as keys are held down.
- After the game input is ticked the physics manager is ticked.
- The physics manager applies gravity to the physics object. It just adds a downwards velocity of -9.81 * framedelta to the physics object velocity. This allows the gravity to accelerate it down.
- The physics manager then checks for whether the physics object hits the ground. Since i am only doing this for the player, i just cast a ray, find the height off the ground and adjust.
- Next the physics manager checks whether the physics object is colliding with any of the walls etc. I cast more rays for this and adjust the movement vector to be parallel with the wall at the reduced speed.
- Finally, once the physics objects velocity has been fine tuned by the various stages, i apply the change in position.
Now the problem that has arisen is that because the wall intersection code stops the physics object (it does this be overwriting the velocity based on the collision), when the game input code gets ticked next frame it removes it's last frame of input (to prevent accumulation remember) causing the object to move in the opposite direction to the last frames controller direction.
Have i overcomplicated this? In terms of code it is pretty simply implemented but i cant think of an elegant solution to combining the affects of forces with the impulses of the controller.
Any ideas what i have done wrong or where to go from here?
Thanks alot.
- At the start of the frame the game input code removes the velocity it added to the physics object from the last frame and adds on the new velocity based on what keys are down for the current frame. The reason for the removal is so the velocity doesn't accumulate over the course of many frames as keys are held down.
- After the game input is ticked the physics manager is ticked.
- The physics manager applies gravity to the physics object. It just adds a downwards velocity of -9.81 * framedelta to the physics object velocity. This allows the gravity to accelerate it down.
- The physics manager then checks for whether the physics object hits the ground. Since i am only doing this for the player, i just cast a ray, find the height off the ground and adjust.
- Next the physics manager checks whether the physics object is colliding with any of the walls etc. I cast more rays for this and adjust the movement vector to be parallel with the wall at the reduced speed.
- Finally, once the physics objects velocity has been fine tuned by the various stages, i apply the change in position.
Now the problem that has arisen is that because the wall intersection code stops the physics object (it does this be overwriting the velocity based on the collision), when the game input code gets ticked next frame it removes it's last frame of input (to prevent accumulation remember) causing the object to move in the opposite direction to the last frames controller direction.
Have i overcomplicated this? In terms of code it is pretty simply implemented but i cant think of an elegant solution to combining the affects of forces with the impulses of the controller.
Any ideas what i have done wrong or where to go from here?
Thanks alot.