How can I update the position for an instance in accordance to its rotation/orientation?

Essentially, I’m trying to animate a battlecruiser nuke part to go towards the city that its required to go to the center of. To do this, I thought it should be possible to use some kind of code to adjust the position of the primary part of the plasma-looking model via the orientation of itself. Moe specifically and put more simply, I want the whole model to move towards the direction that the blue arrow GUI is pointing at:


However, because of the way the vector3 positioning works in Lua, it would mean I would have to adjust 2 vectors at once, and this seems very inefficient to do so. Because of this, I decided to ask for help here.
If anyone can help in any way with this it would be appreciated.

1 Like

I’m not sure I’m understanding it completely, but you might want to use tweenservice if you want it to move smoothly

Essentially I’m trying to move the part at an angle instead of via the regular positioning vectors

You can just use the look vector:

local Part = -- the part
local NewPosition = Part.CFrame.LookVector.Unit * 100 -- The part will move 100 studs in the arrows direction

And then to make it smooth simply use TweenService:

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(5) -- Time to finish the tween

local Part = -- the part

local Anim = TS:Create(Part, TI, {CFrame = Part.CFrame.LookVector.Unit * 100})
Anim:Play()

This makes sense, however this is for an individual part. I need the position of the entire model to be affected using the primary part’s position. However the setprimarypartcframe function i put in doesnt work which can be displayed here

local TS = game:GetService("TweenService")

local TI = TweenInfo.new(5) -- Time to finish the tween

local Part = script.Parent -- the model

local Anim = TS:Create(Part, TI, {CFrame = Part:SetPrimaryPartCFrame(LookVector.Unit * 100)})

Anim:Play()

Instead of using that, simply unanchor all parts except for the main part, then you would weld all the parts together with weld constraints to the main part. Then tween just the main part.

Maybe create a small, invisible part at where it’s supposed to land, then make it so the nuke faces towards the landing spot by doing CFrame.new(pos, lookAt). Then create a BodyVelocity and set the Velocity to the nuke.CFrame.lookVector * (speed). You should not really tween it.