How to make a BodyVelocity Local to its Parts Orientation?

I need help making a zigzagging Projectile, but i cant make it zigzag if the bodyvelocity is relative to the world, so if i make it go in the X direction, it always Travels to the X direction, ignoring the parts orientation

local TweenService = game:GetService("TweenService")
local Time = 0.15

script.Parent.Velocity = script.Parent.Parent.CFrame.LookVector * 50
wait(5)
TweenService:Create(script.Parent,TweenInfo.new(Time,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Velocity = (script.Parent.Parent.CFrame.LookVector) + Vector3.new(80,0,0)}):Play()
wait(Time)
while true do
	TweenService:Create(script.Parent,TweenInfo.new(Time,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Velocity = (script.Parent.Parent.CFrame.LookVector) + Vector3.new(-160,0,0) }):Play()
	wait(Time)
	TweenService:Create(script.Parent,TweenInfo.new(Time,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Velocity = (script.Parent.Parent.CFrame.LookVector) + Vector3.new(160,0,0)  }):Play()
	wait(Time)
end

this code above is telling the velocity to go in a zigzag motion, but depending on the parts orientation, the results vary.

1 Like

If the part’s orientation is changing while the tween is occurring, you cannot do this with TweenService.

You might want to use BodyThrust | Documentation - Roblox Creator Hub instead (but that applies a Force, not a velocity).

Or don’t use TweenService and come up with your own way to modify velocity every frame.

Consider using BodyGyro to rotate your part instead. Then you can use BodyVelocity to consistently update the velocity to the BodyGyro’s target orientation.

Keep in mind there are

CFrame.RightVector
CFrame.UpVector

In addition to LookVector.

1 Like