Slide against Plane/Segment ok, but what about corners?

Started by
6 comments, last by oliii 15 years, 10 months ago
Ive got the sliding part against a line-segement working, but how on earth do i get this to work with a collection of segments? When having a obtuse corner the player starts to "shake" when in the corner as if the player was pushed back an forth, and when in a acute corner there is a "gap" becuase of the minimum_distance to the plane. //Collision Code float length = Vector3.Dot(utility.GetNormalVector(A - B), objCamera.mPos + move_v - A); float viewDot = Vector3.Dot(utility.GetNormalVector(A - B), move_v); if ((Math.Abs(length) < 1) && PlayerInsideSegment(objCamera.mPos+move_v,A,B)) { move_v += (-utility.GetNormalVector(A - B) * (length-1)); } //MOVE_V vforward = (objCamera.mView - objCamera.mPos) * forward; vbackward = -(objCamera.mView - objCamera.mPos) * backward; vleft = classes.utility.GetNormalVector(objCamera.mView - objCamera.mPos) * left * 3; vright = -classes.utility.GetNormalVector(objCamera.mView - objCamera.mPos) * right * 3; //make a completely new move vector by adding all directions. move_v = (vforward) + (vbackward) + (vleft) + (vright); How do you solve your corner problems? i want my engine to be build on segments that i can put anywhere.
Advertisement
One way would be to take multiple collision samples over the player's collision shape. That way the effect of the corner is less obvious (because the player isn't either on segment A or segment B, but partially on A and B), but it's still there. Also, this doesn't work for spheres or other shapes that are colliding with segments at only one point at a time.
I used this way to smooth out movement in a hover craft racing game.

Another way is to apply the collision force (that pushes the player back so he doesn't intersect with the segment anymore) over time. The player will enter the segment slightly, but the movement would be smooth.
I don't understand your code. What is minimum_distance? You mention it but it is not in your code. What is viewDot? You compute it and then never use it. What are you doing with length? Why does it matter if length is less than 1? What is (length-1) supposed to be? I'm not understanding how this is supposed to work at all. What are you even trying to do? Sliding against a line segment could mean different things. Are you keeping the player constrained to the line segment or are the line segments walls?
sorry about the viewDot, that code should not be there at all, i forgot to comment it out.

1 in this case (length-1) is the minimum distance to my linesegment(walls) in my game.

i am sliding the player against the line, but in corner my code isn´t working. thats my question, i want to know how you solve sliding in corners when building a level with linesegment as walls.

You could try using an iterative process along these lines:

Whilst your character still has movement left for that frame repeat the following two steps:

1) Determine how far the character can move using his current velocity vector before he hits a wall. You can do this by casting a ray in the travel direction and intersecting it with your planes. Move the character this far.

2) Remove any elements from the characters velocity vector which lie in the normal direction of the plane he collided with. Go back to step 1 if the character still has more movement available for that frame and his velocity vector is non zero.
[size="1"] [size="4"]:: SHMUP-DEV ::
By "obtuse" and "acute", do you mean "concave" and "convex"?

An easy solution would be to put spherical caps at the end points of the line segments. Right now your walls only push the player in the direction perpendicular to the wall. When the player is near the end points they should also be pushed in the direction that is away from the end point. This will solve all your problems. The player won't be able to get close enough to concave corners to be pushed back and forth (because the corner itself will push them away), and the convex corner will also work correctly.
Does anyone have a samplecode of just basic wallsliding in c++ or c#?

just the basics such as sliding against walls in all kinds of angles, not only 90degree walls.

i am starting to loose hope, this is driving me nuts, i know to little Math and i can´t find good information on the internet that is so basic so i can understand it.

ill eaven pay money for a simple project with sliding against any kinds of obtuse and acute walls! =)
How many times we have to explain this...

http://www.gamedev.net/reference/articles/article1026.asp

Everything is better with Metal.

This topic is closed to new replies.

Advertisement