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.
Thanks it advance
BodyMovers["BodyGyro"].CFrame = CFrame.new(BodyMovers["BodyGyro"].CFrame.Position, Destination)
repeat wait(1)
until System["Main"]["Exterior"]["Base"].CFrame == BodyMovers["BodyGyro"].CFrame
function vectorsAngle(v1, v2)
return math.acos( v1.Unit:Dot(c2.Unit) )
end
local LOOKING_AT_ANGLE_THRESHOLD = math.rad(5)
local vectorToObject = (Destionation - BodyGyro.Parent.Position)
local isPointingAt = vectorsAngle(BodyGyro.CFrame.LookVector, vectorToObject) <= LOOKING_AT_ANGLE_THRESHOLD
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 LOOKING_AT_ANGLE_THRESHOLD = math.rad(5)
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")
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")