# Check Every frame in game

This topic is 3851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by MeshboyHow 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 planeFrame 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.

##### Share on other sites
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

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×