Moving a part in the direction it's facing

Hey, I’m trying to achieve something that seems like it’d be relatively simple, but I’ve got very little experience with CFrame so I’ll need a little help with this.

Basically, I’m trying to have a part move forward continuously dependent on the direction it’s facing so you can alter the direction it moves in by adjusting the rotation of the part.

The following code succeeds at making the object move, but changing the rotation/orientation of the object before running it doesn’t seem to have any effect:

object.CFrame = CFrame.new(object.CFrame.LookVector * n)

Any idea why that is / what I could do to achieve the desired effect?

Thanks!

Looking at the documentation for CFrame.LookVector, it appears that the only issue with the code you posted is that you aren’t adding object.CFrame to object.CFrame.LookVector * n. Try using
object.CFrame = object.CFrame + object.CFrame.LookVector * n.

If you want to use a different method, you could also use
object.CFrame = object.CFrame:ToWorldSpace(CFrame.new(n, 0, 0)), since ToWorldSpace returns its argument transformed to world space (relative to the origin) assuming that the argument is given in object space (relative to object.CFrame).

Both of these methods should work, so it is up to you to decide which to use.

1 Like

This worked, thank you so much! :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.