Jump to content
  • Advertisement
Sign in to follow this  
Jiia

Removing a normal from direction

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

Is this an easy task? Okay, both the normal and direction are normalized direction vectors. But here we go with lamins terms, so I can totally express myself [lol] Wall = Normal Arrow = Direction I know when the arrow is pointing towards the wall, and that's bad. I need to rotate the arrow so that it is not pointing towards the wall, but still as close to its original orientation as possible. I simply want the dot product of the wall and arrow to be zero. I was thinking of a way to "extract" the direction. Some kind of multiply with the direction and an inversed version of the normal, then renormalize. It works perfectly with straight walls, but not when the walls start to slant or tilt from a perfect world axis. I'm looking for the most trouble free way, and would rather not actually rotate the direction. Is there a way I can simply "remove" the part of the direction that is making it point towards the wall? edit: Oh yeah. There is never any Y in either the normal or direction. Just X,Z ground vectors. edit2: Also, the direction will never be fully pointed towards the normal. Dot product is always between -0.8 and 0.0. Thanks for any help [smile]

Share this post


Link to post
Share on other sites
Advertisement
if A and B are your normalized input vectors (and assuming you want to remove B from A)

A' = A - (-B * DotProduct( A, -B ))

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If the dot product of the arrow and the wall* are 0, either the arrow is facing towards the wall or away from the wall. So you can't have an arrow that is _not_ pointing towards the wall and still have the dot product with the wall and the arrow be 0.

*(When you said "wall" for the Normal vector, I'm assuming that you meant that Normal is a vector lying in the plane of the wall, not the normal vector of the wall. Is this what you meant?)

Could you give some more information about what you're doing?

Share this post


Link to post
Share on other sites
Sorry about that. The wall is a normal, as in the normal of the wall. The PC character in my game is controlled by axis input. When the human player is attempting to push towards a wall, the player's character will attempt to walk along side the wall instead. The direction represents where the player wants to walk towards. The "wall" represents a triangle that a small line intersect found in the direction the axis was pressed. But I remove all y direction from this normal before trying to use it.

Gooberius -> I'm gonna try that. I appreciate it.

Share this post


Link to post
Share on other sites
gooberius is right.

the dotproduct gives the amount both vectors have in common. so you extract from the directionvector what it has in common with the normal in the direction of the normal.

note that you can take out the two vector negates there.

Share this post


Link to post
Share on other sites
So just Direction -= Normal * dot?

It seems to work perfectly [grin]
What if the direction was pointing away from the normal? Would this still remove the common axis parts, or amplify them? Also, I need to renormalize this, correct?
Thanks much for the extra explanation, Eelco.

edit: Bah, if the direction was pointing away from the wall, the dot product would be inverted. So nevermind. Thank again [smile]

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!