How do I move a part for example 2 studs in the z axis of the part. When I flip a part 90 degrees and add 2 to its Z position, it changes the X axis instead. How do I make it so it changes the Z axis and not the X axis.
Well that’s because the part is flipped. When a part is flipped (essentially when a 3D or 2D grid is flipped), the axes flip as well. Meaning the positive side of the X axis for example,becomes in the place of the negative one, and vice versa, for all axes.
The part is not moving the X axis instead of the Z axis (from what I’m understanding), it’s going to the other side of the Z axis instead lf the wanted one.
To fix that, simply:
Move 2 studs in Z first,
then rotate.
The X axis might exchange places with the Z axis, if you rotated along the X or Z axis (meaning Vector3.new(90,0,0) or Vector3.new(0,0,90))
It seems that you rotated first.
How to do that with a script? Because in my script the part is rotated to an angle. Not just 90 degrees. That was just an example.
Just flip the two lines you have
part.Position = part.Position + Vector3.new(0,0,2)
part.Orientation = Vector3.new(0,90,0) --or any angle you want
How to do it without rotating the part to 0,0,0 because in my script that does not seem possible/it can make the code dirty.
cl.CFrame = CFrame.new(p1.Position,p2.Position)
local orient = cl.Orientation
cl.Orientation = Vector3.new(0,0,0)
cl.Position = cl.Position + Vector3.new(0,0,-mag/2)
cl.Orientation = orient
Doesn’t work here. ^
Do it with the first line I guess.
CFrame = CFrame.new(p1.Position+Vector3.new(0,0,2),p2.Position)
I have already tried that. It still moves in the global z axis and not the part’s.
Try this:
cl.CFrame = cl.CFrame * CFrame.new(0, 0, 2)
Do you want the global or local Z axis? Your first problem described that it was going in the X axis, assuming that’s the global X axis, this means it’s going in the local Z axis.
I think I didn’t describe it correctly. I meant when the part is rotated and I add 2 in its z axis it moves on global z axis instead of the part’s.
Adding a Vector3 to a CFrame should translate it in global/world space. Multiplying a CFrame by another CFrame would move it in local/object space.
Couldn’t you do something like this? It doesn’t set the part’s rotation to 0.
part.Position = part.Position + Vector3.new(0,0,2)
part.CFrame = part.CFrame * CFrame.Angles(0, 80, 0)