Sliding against a wall [SOLVED]

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

Recommended Posts

I have an object in a 2D game which attempts to move in a certain direction at a certain speed. I wish to modify this attempted movement so that my object will not penetrate other objects, while keeping the tangential component intact (so the object can walk on the floor and slide against a wall or ceiling). All objects in my world are either circular or polygonal in shape. Rotation is impossible, and all movements are approximated by a sequence of rectilinear steps of uniform velocity. Collision detection is perfect. When a collision occurs, a function (which I write) is called, and has access to all the information necessary about the colliding objects (time of impact, contact surface or velocities, among other things). The function resolves the collision (by modifying the movement of at least one object so penetration does not occur) and returns. Finally, there are no 'steps', as collisions and physics are processed only when necessary. Do you have any personal experience or suggestions pertaining to this problem (or, maybe, a solution) ? [Edited by - ToohrVyk on December 31, 2005 10:18:11 AM]

Share on other sites
I understood your problem to find a motion vector parallel to a wall, with a direction dependent on the original motion before colliding, and a length equal to the remaining length the object would have been moved if there were no collision. Is that correct? I suggest this:

You could think of the latest motion vector m to be the sum of a tangential mt and a perpendicular mp component
m := mt + mp
w.r.t. the wall.

The mp is m but projected on the negative unit normal (negative to let it point into the walkable space) -n of the wall
mp = m . -n
w/ "." being the dot-product, of course, so that
mt = m - mp
gives you the principal direction of motion the object should have to slide along. Of course, if running frontal on the wall, the difference in the formula above will become zero and hence the object does not slide.

What remains is the length of the new motion vector. The crinkle where the original motion vector is cut off but completed by the new motion vector is already determined by collision detection, right? It is just the object's extent away from the wall. So the remaining motion length is just the norm of the difference vector of the not reachable point inside the wall and the point of collision just before the wall.

So normalize mt and scale by the above length for the new motion vector.

Share on other sites
What you propose is to modify the velocity of the object right after the collision, which indeed gives a correct result if the collision occurs on an infinite plane (since the new velocity is tangential to the plane).

However, I will usually find myself in the following situation:

The object does indeed slide against the wall, but only does so until it reaches the edge of the object, at which point it starts falling again. My wish is to compute this entire sliding motion, from the initial contact and to the last contact between the two objects.

Share on other sites
Quote:
 Original post by ToohrVykWhat you propose is to modify the velocity of the object right after the collision, which indeed gives a correct result if the collision occurs on an infinite plane (since the new velocity is tangential to the plane).

The collision actually has this effect. Your object would never reach the end of the wall correctly if those new motion isn't computed. So the normalized mt is still the correct direction of the velocity after collision, but the thing is you want to know the moment of time when the sliding has reached the end of the wall...

Well, you know the point of collision, you know the absolute velocity (i.e. speed), you know the geometry of the wall, and you know the direction of motion. So the problem is a least solveable by making a ray to boundary hit test from it, possibly in 2D. Shoot a ray from the point of collision in direction of the new motion, and test it against the boundaries of the wall. (Perhaps a simple rectangular geometry may make this thing easier.) Divide the ray's travel distance by the speed, and you got the time delta the object needs until reaching the end of the wall. The moment of collision is already known, as you've mentioned somewhere above.

Share on other sites
Quote:
 Original post by haegarrThe collision actually has this effect. Your object would never reach the end of the wall correctly if those new motion isn't computed. So the normalized mt is still the correct direction of the velocity after collision, but the thing is you want to know the moment of time when the sliding has reached the end of the wall...

Exactly. Well, my wording wasn't very clear, I admit.

Thank you for your input. I am having a large amount of trouble visualizing the entire physics and collision system in my head right now. I'm sure most of this will seem pretty obvious once I get my head around this.

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• Forum Statistics

• Total Topics
633755
• Total Posts
3013706
×