- Home /
offseting a gameobject from a point, using vector direction and magnitude
Hi Guys, I feel like this should be a pretty simple thing to do, but I seem to be mixing up some things --
I've got point A on a curve. I'd like to offset this point by a fixed distance, perpendicular to the curve direction at that point, resulting in point X.
So far, what i've done is query the point directly in front of point A, point B. I then subtract point B from point A, to obtain the vector AB (or C in the diagram).
This is where I'm starting to get confused:
In theory, using AB.right should give me a vector perpendicular to AB, correct?
I now divide this vector by it's magnitude to normalize it.
I now multiply this vector by the scalar offset I'd like point X to have. This should give me vector D.
Now (really confused) the cross product of point A and vector D should give me point X?
I'd really appreciate it if anyone could point out where my mistake is, or what I should be doing differently.
Thanks, -Juanelo
Hi Jessy, I'm sorry, I really don't understand what that means. Could you elaborate a little?
Answer by simonmc · Jun 05, 2012 at 09:58 PM
The point where you are going wrong is using AB.right. Vector.right is just shorthand for new Vector3(1,0,0)
, not a vector orthogonal to the current instance.
Answer by Berenger · Jun 05, 2012 at 10:38 PM
You need another vector to make a plane so you can find a unique orthogonal vector (see Jessy's comment). I suggest you take Vector3.up and then use Vector3.Cross.
Answer by juanelo · Jun 05, 2012 at 11:03 PM
Ah, fantastic, thanks for the feedback! All along I had thought Vector3.right was local, relative to the vector's direction!
Got everything working now:
Thanks, fellas.
(for those interested, this also helped a bunch: http://unity3d.com/support/documentation/Manual/ComputingNormalPerpendicularVector.html)
Answer by Owen-Reynolds · Jun 05, 2012 at 11:18 PM
Think you could also compute a "look" from A to B, and compute local right from there:
Quaternion ABlook = Quaternion.LookRotation(B-A);
Vector3 X = A + ABlook * Vector3.right * d;
It seems like not enough, but the LookRotation gives you the arrow from A to B and the line going up. That gives enough info to compute a single Right.
Your answer
Follow this Question
Related Questions
Vector direction to point 1 Answer
find location on terrain when touch input 0 Answers
Move Vectors as curve towards Target 1 Answer
Move to a clicked point? 1 Answer
Get new Point from Vector and Angle 1 Answer