Jump to content
  • Advertisement
Sign in to follow this  
ToohrVyk

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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:

sliding

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 this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
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).

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 this post


Link to post
Share on other sites
Quote:
Original post by haegarr
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...


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!