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

Why does this cause the part to move diagonally?

Asked by 8 years ago

I have a part that is anchored and CanCollide true. This is a server script inside of it. It should make the part move forward, but it gradually moves diagonally.

local part = script.Parent
while true do
wait(0.01)
part.CFrame = part.CFrame - Vector3.new(0,0,6)
end

1 answer

Log in to vote
1
Answered by
einsteinK 145
8 years ago

If the part is rotated, it'll make it go diagonally as adding a Vector3 moves it using the global axes. To move it on the local axises, use cf * cf:

part.CFrame = part.CFrame * CFrame.new(-Vector3.new(0,0,6))
-- or
part.CFrame = part.CFrame * CFrame.new(0,0,-6)
Ad

Answer this question