The missile is not working properly

I want to make a homing missile but there is two problems:

  • If the player is moving, the missile will be just twitching near him and explode after a delay or when he stops
  • It’s aiming to the player with a significant delay

This is how I scripted it’s moving:

local RunService = game:GetService("RunService")

	script.Parent.CFrame = CFrame.lookAt(script.Parent.Position, game.Workspace.Reset42227920.HumanoidRootPart.Position)
	script.Parent.CFrame = script.Parent.CFrame + (script.Parent.CFrame.LookVector *, 5, 5))

How to make it aim accurately and fix the movement bug?

1 Like

You could simply make a detection (something like magnitude to check the distance between the player and missile) to see if the player is nearby and then make the missile explode if the player is nearby.

try set network owner to the player it is aiming to.
basically do:
part:SetNetworkOwner(plr) – in the () you need to put the player, and not their character.

The missile is anchored, it doesn’t work with anchored parts.

1st use renderStepped and set network ownership to the player. That is what is causing the twitching due to latency. Also the CFrame scripts can cause the missile to jump over the player. Rather I would clamp max move amount which is in your case 5 to the distance between the player and the missile. This would allow it to remain 5 a majority of the time. However, in the case the player is close by it will go lower then 5 going to the distance between the player and missile, preventing it to jump over the player.

Also I don’t believe you have to multiply the lookVector by a Vector3. Since if it theoretically outputted (1,0.3,0.7), timings that by,5,5) and 5 would result in the same output.

I tried “while wait() do” but the twitching still happens.

How about doing something like this:

	local startCFrame = CFrame.lookAt(script.Parent.Position, game.Workspace.Reset42227920.HumanoidRootPart.Position)
	script.Parent.CFrame = startCFrame + (startCFrame.LookVector *, 5, 5))

So it won’t set the CFrame twice.

1 Like

while wait() and Stepped are two different things. wait() is much slower. If you every experience further latency try doing the script in a the local script and setting network ownership to the player so u can use RenderStepped