Missiles rotating vertical when CFrame is used to tween their position but attempts to rotate them are fruitless

Alright so basically I’m trying to make these cool missiles for a boss fight I’m making, they are supposed to face a target position and move towards it.

should be simple except that said missiles have to be moved with CFrame due to how they were constructed ( direct position changes will stop welded parts from being moved with it ), it has a central MovementPoint which is what is actually moved and everything else uses WeldConstraints to stay welded onto it.

using CFrame for this comes with a problem though, rotating the missiles towards the point can’t be done within a Tween, at least not very easily.

when a CFrame tween is used on the missiles, it will make them rotate vertically during it, ending with vertical missiles instead of them facing the target.

what I want to achieve instead is the missiles to look at the target and not look away from it, the problem is however is using CFrame.new() and CFrame.lookAt() in one or individual tweens sends them 10s of millions of studs away from 0,0,0.

the construct I’ve tried using looks a bit like this

	local TweenInf = TweenInfo.new(Thing2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

	local Finish = {CFrame = CFrame.new(Target) * CFrame.lookAt(script.Parent.MovementPoint.Position, Target)}

	local Tween = TweenS:Create(script.Parent.MovementPoint, TweenInf, Finish)

the variables:
Thing2 is just a timing variable to move the missiles at the same speed every time they are fired based on distance
Target is the Target position that the missile moves to and is a Vector3 value
the rest is declared and shown in that code block

assistance here would be greatly appreciated

1 Like

According to the CFrame wiki entry, CFrame.lookAt() functions as CFrame.new() does in terms of parameters. Meaning: do not multiply CFrame.new with CFrame.lookAt in your end goal.

Try this:

local TweenInf = TweenInfo.new(Thing2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

local Finish = {CFrame = CFrame.lookAt(Target, Target)} -- go towards Target facing Target

local Tween = TweenS:Create(script.Parent.MovementPoint, TweenInf, Finish)

The exact entry states:

CFrame.lookAt ( Vector3 at, Vector3 lookAt, Vector3 up = Vector3.new(0, 1, 0) )
Creates a new CFrame located at at and facing towards lookAt , optionally specifying the upward direction (by default, (0, 1, 0)).

This function replaces the CFrame.new(Vector3, Vector3) constructor (see above) which accomplished a similar task. This function allows you to specify the up Vector, using the same default as the old constructor.

You were essentially multiplying CFrames, thus getting the offset you were getting.

it just kinda did the same thing

Capture

oh also I forgot to mention that when it does this weird offset it also sets the Position X and Z to 0