I'm currently trying to create a missile that has a limitation on how quick it can turn. But i'v ran into a weird issue where that it doesn't take the route i expected and im completely confused why it takes that route. It does eventually get to its target after a while or short but its quite random and inefficient.
https://gyazo.com/a8da38ce9dbce5ee63737b369dfa8623 - Gif of its movement This is a part of the code that calculates the way it rotates
while nukeCollided == false do
swait()
if nuke.Position.Y < (projectileOrigin.Y+nukeTargetHeight) and nukeAtTargetHeight == false then
-- Rise to target height
nuke.Position = nuke.Position + nuke.CFrame.LookVector
elseif nuke.Position.Y > (projectileOrigin.Y+nukeTargetHeight) then
nukeAtTargetHeight = true
end
if nukeAtTargetHeight then
local nukeVelocityDir = nuke.CFrame.LookVector
local nukeTargetDir = CFrame.new(nuke.Position, player:GetMouse().Hit.Position).LookVector
local nukeDegreesToTarget = math.deg(math.acos(nukeVelocityDir.unit:Dot(nukeTargetDir.unit)))
local nukeAxisToTarget = nukeVelocityDir:Cross(nukeTargetDir)
local nukeTurnAmount = math.clamp(nukeDegreesToTarget, -nukeTurnRate, nukeTurnRate)
if nukeDegreesToTarget > 0 then -- Temp stops nukedeg from NaN and removing fake rocket
local rotCF = (CFrame.fromAxisAngle(nukeAxisToTarget ,math.rad(nukeTurnAmount)) * nuke.CFrame)
local x, y, z = rotCF:ToEulerAnglesYXZ()
nuke.CFrame = CFrame.new(nuke.Position) * CFrame.fromEulerAnglesXYZ(x,y,z)
nuke.Position = nuke.Position + nuke.CFrame.LookVector
end
end
end
Currently im just very confused with the way it gets to its target by circling around multiple times getting slightly lower each time before it reaches its target. No idea how to get it to take the right turn if anyone knows how to make it get to the target normally would be much appreciated.
