Check Every frame in game

Started by
3 comments, last by Rasmadrak 15 years, 10 months ago
For my collisiondetection i check if the player is < 0.3f distance to a plane, this isnt working because when the player is <0.3f he has come to close to the plane. How do you check every frame? i want to save the status before player moved and compare this one against when player moved so i can back the player if he is to close. Also, i can perform this: Frame 1: Player is Facing plane Frame 2: Player is not facing plane and distance is to short = player hit the plane. basically i need good structure for checking every frame in my game app so i can use old player locations. Right not i can sortof do this because i always have the pos before the player moved but i think checking everyframe is more accurate then check before movement.
Advertisement
I don't know much about this, but I think what you are looking for is called "continuous collision detection". Doing a google search brings up some interesting results.

BTW, what you are describing is called "frame-to-frame-coherence". Google is very helpful here as well.
As per my recent notes I don't see anything XNA-specific about this question. I'm moving it to 'Game Programming' for now as this seems as much a logic and programming issue as it does a maths/physics one.


Cheers,
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Quote:Original post by Meshboy
How do you check every frame?

What? You call your collision routine before or after every time you draw your scene?

Quote:i want to save the status before player moved and compare this one against when player moved so i can back the player if he is to close.

You're not making much sense to me... but if I understand correctly you want to know if the player is GOING TO be too close to the plane.
You can advance the player position one timestep (newPosition = oldPosition + velocity) and check that new position against the plane.

Quote:Also, i can perform this:

Frame 1: Player is Facing plane
Frame 2: Player is not facing plane and distance is to short = player hit the plane.


I'm trying to read between the lines here, so correct me if I'm wrong. Are you asking this question because your player gets stuck in the plane and you see him shaking as he does?
If so, there is an additional check (other than just the distance) you can do to see if there REALLY was a collision. You can check if the player is moving TOWARDS or AWAY from the plane. If the player is moving towards the plane AND within the collision distance you have a collision.
However, if he is moving away from the plane AND within the collision distance you don't have a collision.
Basically you take the dot product of your plane's normal and the velocity vector. If it's smaller than 0 your player is moving towards the plane, if it's greater than 0 it's moving away from the plane.
STOP THE PLANET!! I WANT TO GET OFF!!
You can also do a double check to see if the player/object has passed through an triangle.

First check the sign (+/-) of the player position to the triangle.
Then check the sign of the player position + velocity change.
If these differ from eachother the player has passed through the triangle.

/Robert
"Game Maker For Life, probably never professional thou." =)

This topic is closed to new replies.

Advertisement