How do I move a part forwards?

Hello I’m trying to move a part… but it’s not what you think! moving a part forward works, but I want to move it forwards in whatever direction its looking. so If its looking sideways, move it sideways forward. Here is an example:
image
image
see how to part moves forwards in the direction the part is looking and not just increasing its Z axis.

1 Like

You would have to multiply a CFrame relative to that part’s CFrame.

Consider that the direction the part is moving towards is relative to it’s z-axis. Your code would look something like this:

part.CFrame = part.CFrame * CFrame.new(0, 0, -1) -- Moves part forward by 1 stud
part.CFrame *= CFrame.new(0, 0, -1) -- This does the same thing

You can do this with any axis relative to the part’s CFrame.
More here.

7 Likes