Jump to content
  • Advertisement
Sign in to follow this  
CodeImp

Sliding vector from velocity vs a wall

This topic is 4639 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

Or whatever you want to call it... I'll make my case clear with this drawing: Image Hosted by ImageShack.us W is a wall along which I want to slide the purple object. The object has velocity vector A and I want to know the sliding vector C. I know C definitely does not have the same length as A and I know C = A + B, but the question is, how do I find B without knowing C? I have read the articles on collision detection around here and they did not gave me a clear answer, thus my post here, I hope someone can help ;) I tried using the normal of W scaled to the length of A, and got close, but then C is not the accurate sliding vector (its direction is a little off) so that can't be the correct math.

Share this post


Link to post
Share on other sites
Advertisement
You could split A into a part perpendicular to the wall (I assume that is what you meant with B) and a part C along the wall.

With N being the (unit length) normal of the wall, pointing into the room where the object is, then
N dot -A := -1 * ||A|| * cos<N,A>
will result in the projected length of A against N. Hence
B := A * ( N dot -A ) / ||A||
and, as you already have stated,
C := A - B

If e.g. the object run perpendicular to the wall (and you use unit normals for simplicity), then
N dot -A = ||A||
and
B = A
and
C = 0
what is correct.

EDIT: Sorry, the first posted version has had A and C confused.

Share this post


Link to post
Share on other sites
But I don't know C, I only know A and the wall W and want to know B (the force the wall gives in response to A) so that I can calculate C = A + B. (I want to calculate it that way, because that math also works when the object is only touching the end (corner) of the wall in which case it slides in a direction not parallel to the wall.)

Share this post


Link to post
Share on other sites
Appendix: The object touches the wall in a single point. Furthurmore the wall has a single normal only if not doing a more elaborate stuff. If you want the object "go around the corner" of the wall, it may be necessary to compute the normal on the fly, e.g. as the unit vector pointing from the contact point to the center of the circle. So the normal will "wrap around" the corner of the wall.

Share this post


Link to post
Share on other sites
Yes, I have already worked that out. In my case N is the vector from the nearest point on the wall to the center of the object and B = A * (N dot -A) / ||A|| and then C = A - B, did I understand that right?

Share this post


Link to post
Share on other sites
I think that is right as long as your N is of unit length. (If not, then there is an additional dependence of the length of N!)

Share this post


Link to post
Share on other sites
Quote:
Original post by CodeImp
Yes, I have already worked that out. In my case N is the vector from the nearest point on the wall to the center of the object and B = A * (N dot -A) / ||A|| and then C = A - B, did I understand that right?


You meant: B = N * (N.A)

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
You meant: B = N * (N.A)

Ahh, yes. Damned. Thx ToohrVyk.

N * (N dot A)
will shift the object back against N, while
A * (N dot -A) / ||A||
will shift it back from where it has come. The latter formula is typical for "non sliding" collision correction!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!