How to use Vector3.Angle using an Objects position instead of the World Origin.

I casted a ray from point B to a sphere ( The sphere aint at the origin point ).

Using the Vector3.Angle, I cant seem to find the right output. From point B, the Vector3.Angle should output 90. And if from Point A, it should Output something around 45. The problem is that it uses the originn point as reference. So how can I use an objects position as reference instead? The Vector3.Angle syntax only takes 2 parameters.

Hopefully the explanations done in plain english, I’m still learning Unity

1 Like

What are you trying to find the angle between? A and B? A, B and the sphere’s tangent?

In order to get the angle between two points relative to some third point, you construct the vectors from the third point to the first and second points, and get the angle between those two vectors.

I’m sorry but how should I write that in code? That’s exactly what I’m trying to look for

// Assume you have these points:
Vector3 pointA, pointB, referencePoint;

//You construct:

var toPointA = pointA - referencePoint;
var toPointB = pointB - referencePoint;

var angle = Vector3.Angle(toPointA, toPointB);
2 Likes

Omg dude your’re great. Didn’t think it was actually this simple. Thanks for the Help!!

1 Like