Hello! I want to know how to make a part move in the direction it is facing. I tried using ToWorldSpace() but it only faced in a certain direction but didn’t move there. I also tried bodyVelocity but the direction doesn’t change. Can someone please tell me how to make a part move in the direction it is facing? Thanks!
You can use TweenService
and LookVector
to accomplish this:
local part = -- Your part here.
local distance = -- Distance the part should move.
local tween = game:GetService("TweenService"):Create(part, TweenInfo.new(1, Enum.EasingStyle.Sine), {CFrame = part.CFrame + (part.CFrame.LookVector * distance)})
tween:Play()
Let me know if this isn’t what you need, or if doesn’t work.
Thank you so much! But I am doing this on the server and tweening will lag. Is there a way to use bodyVelocity to do this?
The same thing, you use the LookVector as the velocity, multiplied by the speed of the velocity using disntance.
Ok. Let me try them and then I will set as solution.
You can use BodyForce
BodyForce.Force = Vector3.new(0, 0, 5000) * part.CFrame.LookVector
You will have to change the force from 5000
to anything you like, It depends on the part you want to move
Also to use Tween without lagging, set the network owner of the part to nil
(server)
part:SetNetworkOwner(nil)
You add the bodyVelocity inside a part, set MaxForce
and P
to what you want.
Then inside the script you should add:
local BodyVelocity = script.parent:WaitForChild("BodyVelocity")
BodyVelocity.Velocity = Vector3.new(0, 0, 5000) * part.CFrame.LookVector
Vector3.new(0, 0, 5000)
: is the velocity,
* part.CFrame.LookVector
will make the part always go forward, or at the direction you want
If you want a specific position, I would recommend Tween Service
I have to go to sleep now. If it worked tomorrow, I will set it as the solution. Thanks again!
im sorry to ask this litteraly 3 years later, but how can i modify this to tween a model?