So I’ve been lately trying to develop a tracking system for my missiles in a game I’m developing, and the code I’ve been using doesn’t appear to work. At all.
The video is in the link above.
As you can see in the video, the missile just freaks out upon launch. Like it is completely ignoring the code I’ve given it. At some point, the missile goes so out of target, that it isn’t even visible anymore. I am completely confused and lost about what to do.
It seems that not a lot of people have had the same problem I did, because I couldn’t find anything similar inside the forums.
So far I’ve tried removing the “AlignOrientation” constraint and using CFrame.LookAt instead of CFrame.new(position, position)
I’ll copy paste the code for the thrust/speed and the way the missile is meant to track the target (and register the hit).
local module = {}
function module.Thrust(enginePart)
while enginePart.Parent == workspace do
wait(game:GetService("RunService").Heartbeat)
enginePart["Smoke Emitter"].ParticleEmitter.Enabled = true
enginePart.LinearVelocity.Enabled = true
enginePart.LinearVelocity.VectorVelocity = enginePart.CFrame.LookVector * 1000
game.ReplicatedStorage.TriggerSeekerEvent:Fire()
end
end
return module
(the script inside the missile runs the same code from the module)
local eventToListen = game.ReplicatedStorage.TriggerSeekerEvent
eventToListen.Event:Connect(function()
local lookPart = script.Parent
local Rs = game:GetService("RunService")
local target = game.Workspace.Target
local missilerayparams = RaycastParams.new()
missilerayparams.FilterType = Enum.RaycastFilterType.Exclude
missilerayparams.FilterDescendantsInstances = {lookPart}
while lookPart.Parent == workspace do
wait(Rs.Heartbeat)
lookPart.CFrame = CFrame.lookAt(lookPart.Position, target.Position)
local ray = workspace:Raycast(lookPart.Position,lookPart.CFrame.LookVector*20,missilerayparams)
if ray then
print(lookPart.Name .. " Has Hit " .. tostring(ray.Instance) .. "!")
game.ReplicatedStorage.targetDestroyedEvent:Fire()
lookPart:Destroy()
target:Destroy()
end
end
end)
Please help me! I have 0 idea on what to do.