Making a projectile always look towards the target

Heya!
I’ve recently been trying to make a projectile for a tower in my tower defense game.
I want the projectile (in this case a missile) to always face towards the target so it looks like it’s actually flying towards it.

My current code looks like this:

new:PivotTo(CFrame.lookAt(cframe.Position, enemyModel.PrimaryPart.Position))
	new.Parent = workspace.CurrentCamera
	
	local distance : number = (cframe.Position - enemyModel.PrimaryPart.CFrame.Position).Magnitude
	local travelTime : number = distance / projectileSpeed
	local newCFrame = enemyModel:GetPivot() + new.PrimaryPart.CFrame.LookVector
	
	local info = TweenInfo.new(travelTime, Enum.EasingStyle.Linear)
	local travelTween = tweenService:Create(new.PrimaryPart, info, {CFrame = newCFrame})
	travelTween:Play()

“New” being the cloned projectile (model).

But for some reason it resulted in weird stuff like in the image:
Bildschirmfoto 2024-12-12 um 21.03.37
As you can see, the missiles start to point up weirdly near the end of their lifetime.

How can I go about fixing it?
Thanks!!

1 Like

it’s because you only make it look towards the target at the beginning.
so initially it faces the tatget because you did CFrame.lookAt but then you’re tweening the projectile to target’s CFrame without any rotation.

Try replacing:

local newCFrame = enemyModel:GetPivot() + new.PrimaryPart.CFrame.LookVector

with

local enemyPos= enemyModel:GetPivot().Position
local newCFrame = CFrame.lookAt(enemyPos, enemyPos + new.PrimaryPart.CFrame.lookVector)

Uhhh. Now they just spinn idk why lol.

1 Like

Makes sense. But how would I assign the rotation to the final cframe?

Thats odd, testing it in my own place and it worked fine.

Are you sure that the projectile’s primary part is oriented correctly? As in the front faces faces front, left faces left etc.

The faces are not correct. That’s all I know. But shouldn’t that make the missile just fly with the wrong face upfront and not spinn?