Hi, I’m trying to determine when the BodyGyro of a part is looking directly at it’s target or whether it’s within a 5 degree radius before furthering the script?
Is this at all do-able?

I use a simple rotation method - However I’m aware there is no 100% way to allign these accurately hence the radius.

``````	BodyMovers["BodyGyro"].CFrame = CFrame.new(BodyMovers["BodyGyro"].CFrame.Position, Destination)
repeat wait(1)
until System["Main"]["Exterior"]["Base"].CFrame == BodyMovers["BodyGyro"].CFrame``````
1 Like

Something like this:

``````function vectorsAngle(v1, v2)
return math.acos( v1.Unit:Dot(c2.Unit) )
end

local vectorToObject = (Destionation - BodyGyro.Parent.Position)
local isPointingAt = vectorsAngle(BodyGyro.CFrame.LookVector, vectorToObject) <= LOOKING_AT_ANGLE_THRESHOLD
``````
1 Like

Hi - This seems to launch nearly immediately, regardless of whether or not the Part is facing it’s target?

``````	local function vectorsAngle(v1, v2)
return math.acos(v1.Unit:Dot(v2.Unit))
end

local vectorToObject = (Destination - System["Main"]["Exterior"]["Base"].Position)
local isPointingAt = vectorsAngle(BodyMovers["BodyGyro"].CFrame.LookVector, vectorToObject) <= LOOKING_AT_ANGLE_THRESHOLD

repeat wait() until isPointingAt

print("Facing direction")``````
1 Like

Oh, sorry. I misunderstood you because of this:

Change it to

``````local gyroPart = BodyMovers["BodyGyro"].Parent
local isPointingAt = vectorsAngle(gyroPart.CFrame.LookVector, vectorToObject) <= LOOKING_AT_ANGLE_THRESHOLD
``````

Also, you’re only check if it’s pointing close enough once, it needs to happen every loop:

``````repeat
wait()
local vectorToObject = (Destination - System["Main"]["Exterior"]["Base"].Position)
local isPointingAt = vectorsAngle(BodyMovers["BodyGyro"].CFrame.LookVector, vectorToObject) <= LOOKING_AT_ANGLE_THRESHOLD
until isPointingAt
``````
1 Like

Hi, similar situation. I’ve attached the outcome.

``````	local LOOKING_AT_ANGLE_THRESHOLD = math.rad(5)

local function vectorsAngle(v1, v2)
return math.acos(v1.Unit:Dot(v2.Unit))
end

local gyroPart = BodyMovers["BodyGyro"].Parent
local vectorToObject = (Destination - gyroPart.Position)
local isPointingAt = vectorsAngle(gyroPart.CFrame.LookVector, vectorToObject) <= LOOKING_AT_ANGLE_THRESHOLD

repeat
wait()
local vectorToObject = (Destination - System["Main"]["Exterior"]["Base"].Position)
local isPointingAt = vectorsAngle(BodyMovers["BodyGyro"].CFrame.LookVector, vectorToObject) <= LOOKING_AT_ANGLE_THRESHOLD
until isPointingAt

print("Facing target")
``````