Getting angle from part in a 3D Space

Hello !

I’m currently having some issues with setting a target’s position relative to the player.

My problem is I have no clue on how to get the angle from this target.

For example we have the variable offTargetAngle which is supposed to contain our angle OFF the target in a 3D space.

There’s a schema :

We could use trigonometry if it was a right triangle, but in most cases, it wouldn’t.

Thanks for answering :slight_smile:

Extra information : I’m basing myself on Vector3.Angle method which gets the angle between two targets on Unity

A player’s character is a fixed point in space, not a line or a vector, so is the target. What exactly is the black arrow supposed to represent? Is it supposed to mean the direction the character is moving in? If so, how long is the distance of the green line inside the black line?

I’ve completed my post a tad bit more :

Extra information : I’m basing myself on Vector3.Angle method which gets the angle between two targets on Unity

I’m trying to get the behavior of Vector3.Angle used on Unity, here’s a part of the wiki description :

I still don’t quite understand how that would help in your example, but getting the angle between two vectors in Roblox can be done with the mathematical definition.

local function angleBetween(v1, v2)
    return math.acos(v1:Dot(v2)/(v1.magnitude * v2.magnitude))
end
1 Like

I don’t know why you use the vocabulary “mathematical definition” when you could just use the word trigonometry. I never knew vector:Dot(vector) existed, I might check documentation.

Anyway, thanks for the help !