Finding the Target Angle between two vectors

Not at all, the height (y) of the target part varies, depending on where the ray hits.

Ok that’s probably fine. Try something like this:

local a=baseplate.CFrame.lookVector*-1,a.Z)
local b=(,baseplate.Position.Y,target.Position.Z)-baseplate.Position).Unit,b.Z)

local cost=(a:Dot(b))/(a.Magnitude*b.Magnitude)
local t=math.acos(cost)

I can walk you through the math later if you want. But I really want to see how this does first. :slightly_smiling_face::

1 Like

local cost=(a:Dot(b))/(a.Magnitude*b.Magnitude)

Is there an extra parenthesis here?

A lone parenthesis? I don’t see one. Is your HingeConstraint’s ActuatorType set to Servo?

Yeah, it is. :eyes: :thinking: :smile:

Oh ok. That might mean we will need to add our angle to the current TargetAngle. :thinking:

It will be returned in Radians correct? Not Degrees?

It will return as degrees not radians.

Update: Actually, let me check.

I was wrong. It returns in radians.

1 Like

Okay I was wrong as well… the front vector is actually facing towards the right of the mortar… Which means the baseplate’s front vector is actually negative RightVector

1 Like

Just to update this so far:

local a=baseplate.CFrame.RightVector*-1,a.Z)
local b=(,baseplate.Position.Y,target.Position.Z)-baseplate.Position).Unit,b.Z)

local cost=(a:Dot(b))/(a.Magnitude*b.Magnitude)
local t=math.acos(cost)
local angle=math.deg(t)

It’s partially working, it won’t rotate left at all.

Output of T:

  80.393969837658 (x2)
  80.545715200787 (x6)
  118.32042315943 (x2)
  111.91522450319 (x3)
local A = Baseplate.CFrame.RightVector * -1
A =, A.Z)
local B = (, Baseplate.CFrame.Y, Hit.Z) - Baseplate.CFrame.p ).Unit
B =, B.Z)
local Cost = ( A:Dot(B) ) / (A.Magnitude * B.Magnitude)
local T = math.acos(Cost)

I use a bunch of capitals… haha a bit non conventional.


That’s normal. I actually expected that to happen. (just hadn’t mentioned it yet) :stuck_out_tongue:
We need a way to figure out when our angle should be subtracted. Give me a minute to try and figure something out. :thinking:


Will every mortar’s base part always have the save orientation? (I hope so :stuck_out_tongue:)

Lol, nope. The way it spawns is it’s placed directly in front of your character on the ground. So it’s facing the same direction as the player.

This actually turned out to be a lot more difficult than I expected, Actually the parabola seemed easier. But that’s probably because I looked up the formula. Haha

Could you try adding this after the angle is calculated:

local x=nozzle.CFrame:PointToObjectSpace(target.Position)

After you do that, could you hit play and show me what happens similar to what you posted above?

1 Like

  80.549499511719 (x51)

Sorry, could you do that again and sweep between the left side of the nozzle and the right side. I’m trying to figure out if you get a negative output when your mouse is to the left of the nozzle and a positive output if it’s on the right side. Your mouse stayed to the left of the nozzle the entire time. I’m pretty hopful since I saw mostly negative numbers. But try keeping the mouse over on the other side to see if you get positive numbers.

  -5.5263962745667 (x38)