- Home /
Trouble with working out angle between 2 points
I'm having trouble working out the angle shown. Basically, I need the angle to be just affected by the y axis if you can see what I mean? I also need the rotation of the non selected capsule to be taken into account. What I have so far works when (the non selected) capsule isn't rotated and its forward is (0,0,1).
Here's my line of code that works when there's no rotation.
yAngle = Vector3.Angle (transform.forward, new Vector3 ( (playerBounds[i].x - transform.position.x) * transform.forward.x, playerBounds[i].y - transform.position.y, (playerBounds[i].z - transform.position.z) * transform.forward.z ) );
![alt text][1]
playerBounds[i] is just the position of the selected capsule, and anything else is the transform of the non selected capsule. [1]: /storage/temp/26531-unity+angle+help.jpg
Your code and your words don't match to me, so I'm unsure of what you want. I can suggest a couple things to explore. If this is 2D (just X and Y), you can get an angle of a vector relative to Vector3.right using $$anonymous$$athf.Atan2(). Note that the parameters go into the function y,x. But given your drawing, reversing them might give you what you are looking for.
Second, Vector3.Angle is unsigned. If that works for you fine. If you are looking for a signed angle:
function SignedAngle(v1 : Vector3,v2 : Vector3, normal : Vector3) : float {
var perp = Vector3.Cross(normal, v1);
var angle = Vector3.Angle(v1, v2);
angle *= $$anonymous$$athf.Sign(Vector3.Dot(perp, v2));
return angle;
}
Your answer

Follow this Question
Related Questions
Rotate an object using joystick 1 Answer
Rotate vector around vector? 2 Answers
Trouble with Vector3.Angle() and RotateAround() 1 Answer
Flip an object by 180° (C#) 0 Answers