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

Part Moves Diagonally?

Asked by 7 years ago

I have a part moving, and for some reason it gradually moves diagonally. The part is anchored and cancollide true. This is a server script inside the part.

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

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

What are you trying to do with the script? If you're just trying to set it at a certain CFrame, you would want to do

part. CFrame = CFrame.new(x,y,z)

If you want to rotate it, I think you would want to do

part.CFrame = part.CFrame * Cframe.Angles(x,y,z).

I think when you're multiplying by CFrame.new(Vector3.new(x,y,z), you're moving the part from its current CFrame to the Vector3, a position in the Workspace, which is why it is gradually moving diagonally. Even if it is Anchored and cancollided, the script will still move it to its new position.

0
Im trying to make it move gradually by adding a bit each time. CheekySquid 78 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I'm winging it,

So when multiplying CFrames, the rotation properties of both can interfere with direction. To make the object move in a direction globally, multiply the position with the CFrame you want.

local part = script.Parent
while wait() do
    part.CFrame = CFrame.new(part.Position)*CFrame.new(0,0,-6)
end

Let me know if that works for you.

Good Luck!

If it did work, and I proved to be helpful, please don't forget to accept my answer.
0
This caused this error: attempt to multiply a Vector3 with an incompatible value type or nil CheekySquid 78 — 7y
0
Edited User#11440 120 — 7y

Answer this question