Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I move a part a specific direction no matter what direction the part is facing?

I have a part which I need to animate. I need to move it 0.1 studs backwards in the direction I'm looking.

The problem for me: My front is the parts left. I need to move it backwards base on the direction I'm facing.

Since I can't guarantee that the part will always be facing a specific direction, I need to know how I can move it no matter what direction the part is facing.

I've made several attempts. All of which achieved nothing I was trying to achieve.

Thanks ahead of time for the help!

1 answer

✓ Accepted answer

#What the problem is You're changing the object's CFrame to the object space when you should really just be moving it to world space.


#WorldSpace In order to get a CFrame from world space there are actually 2 methods. Using the toWorldSpace method or multipliying 2 CFrame values together.

part.CFrame = part.CFrame:toWorldSpace(CFrame.new(0,5,0)) --Take the part's cframe and get the position if you were to move the object exactly 5 studs up. No matter how it's rotated.

part.CFrame = torso.CFrame*CFrame.new(0,5,0) --Change the part's cframe to 5 studs above the torso. No matter what rotation the torso or the part is.

#Final Product

while wait() do --Every 1/30th of a second(Standard YouTube frame rate)
	part.CFrame = part.CFrame:toWorldSpace(CFrame.new(0,0,-1)) --Move part 1 stud backwards.
end


Hope it helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.