Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
AZDev 590 Moderation Voter
7 years ago

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

Log in to vote
1
Answered by 7 years ago

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!

Ad

Answer this question