I have currently a player model setup in a GameObject class which stores velocity, position, collision sphere, rotation, etc.
Now, I have gravity kick in by saying...
Code: Select all
player.VelocityY += 0.4f;
player.PositionY = player.VelocityY;
Now, the collision spheres meet...
Code: Select all
if (player.CollisionSphere.Intersects(groundCollision))
{
player.VelocityY = 0.0f;
}
Someone suggested to limit the velocity (which makes sense) so that I don't keep increasing speed slowing down player.
How would I go about doing this?
I'm pretty sure I got some form of working collision for regular stuff not based on gravity... here is some psuedo code for it, if you can find a better solution or know one (which is most likely true) then tell me what you got.
Code: Select all
if (player.Collision.Intersects(object.Colisision))
{
if (player.PositionX <= object.PositionX)
{
player.PositionX -= 0.1f;
player.VelocityX = 0.0f;
}
// repeat for greater than and Z for less and greater than
}
Thanks,
LeonBlade