Sign in to follow this  
Panties

fps collision detection bug

Recommended Posts

I am currently working on a small fps. I'm having a bit of trouble detecting collison between the camera and a wall. Right now I am testing it with just 1 wall in the world. Each frame, I plug in the camera's position into the plane equation for the wall. If the result is negative, I know the camera is behind the wall (there is a collision). If there is a collision, the camera has to be pushed back to the front side of the wall. I use the camera's current position and previous position to get a vector of the camera's movement between this frame and the last. I find the dot product of this movement vector and the wall's normal. The camera is shifted by a vector that is the absolute value of the previously mentioned dot product times the wall's normal vector. This works fine, except for one case. If you are facing the wall striaght on, or nearly straight, and hit the wall while strafing and going forward, you just barely go through the wall. When you let go of the keys, you get pushed back onto the correct side of the wall. The same thing happens if your back is to the wall. In other words, the bug occurs when the absolute value of the dot product of the movement vector and the wall's normal vector is maximized (or close to maximized). Any idea on why this situation is different and what I can do about it?

Share this post


Link to post
Share on other sites
Quote:
If you are facing the wall striaght on, or nearly straight, and hit the wall while strafing and going forward, you just barely go through the wall. When you let go of the keys, you get pushed back onto the correct side of the wall. The same thing happens if your back is to the wall.

In other words, the bug occurs when the absolute value of the dot product of the movement vector and the wall's normal vector is maximized (or close to maximized).

Any idea on why this situation is different and what I can do about it?
It might just be me, but I didn't follow that. What is the bug exactly? Perhaps you could explain it again. (Unless of course someone else understands and answers first!)

Share this post


Link to post
Share on other sites
You are mixing things it seems. You are doing a lot of extra work just to finally push the camera along the plane normal (cf. "... the previously mentioned dot product times the wall's normal vector.").

The distance to plane from B (ex. current camera position) can be used directly with the plane normal to get the vector that will bring back B on the plane surface.

Something like: F = B + n * (distance + safety_epsilon); where F is the point on the plane surface is sufficient.

Note that you will have no "friction" when doing this, just a perfect sliding collision. If you want to add friction this is where the old position come into play. For discrete collision detection like you are trying to do now you can completely ignore the old position at first.

Share this post


Link to post
Share on other sites
Sounds like your setup is doing this:

Test [+ resolve] collision
Check and incorporate this frame's input
Draw scene

when it should do this:

Check and incorporate this frame's input
Test [+ resolve] collision
Draw scene

But then again, I'm probably way off.

CJM

[Edited by - CJM on May 29, 2005 3:50:01 AM]

Share this post


Link to post
Share on other sites
Sounds like you're rendering your scene before the pushback calculation takes place. It's probably not noticable except at 90 deg because the near clipping plane is close enough to the camera that its only apparent head-on.

What CJM said in the previous post is probably the best way to fix this or as a quick fix adjust the near clipping plane to be smaller or make the collision offset from the wall greater.

Share this post


Link to post
Share on other sites
The mis-ordering of input and collision detection is a good idea, but I'm pretty sure I have it in the right order. I'll double check though.


Quote:
Original post by Kristafarii
or as a quick fix adjust the near clipping plane to be smaller or make the collision offset from the wall greater.


I tried setting the epsilon to 3.0 just to see what would happen. I stayed a great distance away from the wall, but when I faced it and went forward while strafing, I still went through the wall.

I'll try reducing the near clipping plane also.

Share this post


Link to post
Share on other sites
Have you solved this problem? It sounds very familiar to an issue I had developing collision detection for fps type game.

In the end I resorted to defining the wall logically as a polygon (with an offset away from the wall) and testing if the camera's current position to new position 2D vector crossed any of the wall's sides.

Not the best solution but it allowed me to continue developing the engine with a note to come back and fix the problem later properly.

If you've fix it please post the solution.

Share this post


Link to post
Share on other sites
I reduced the clipping plane from 0.1 to 0.01, which had no effect. I haven't solved it yet. I have exams coming up, and I don't plan to be sober for the next few days after that, but I'll solve it some time in the near future.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this