Is it possible to lock just one axis on a part?

Hey guys, I was curious if there was a way to lock the a parts movement on just one axis. I know you can can use prismatic constraints to do that somewhat, but what if you wanted to lock it only on one. For instance, what if you want a part to be movable on the X and Z axis, but locked on the Y? I don’t care if it’s done by using script, or a constraint of some sort, I just want to know if it’s possible.

Thanks, KDJ :parrot:

4 Likes

I’d imagine an easy method of doing that is to use BodyPosition and changing its MaxForce and Position property to suit your needs.

2 Likes

Most definitely possible. You can try using CFrame, Vector3 or even BodyMovers as @ShadokuSan as said.

--CFrame
PartNameHere.CFrame = CFrame.new(10, PartNameHere.CFrame.p.Y, 10) -- or replace Y with 0, but usually ill advised

--Vector3
PartNameHere.Position = Vector3.new(10, PartNameHere.Position.Y, 10)

I suggest using CFrame over normal position because only using position has its fair share of problems, plus CFrame can do what position does but with more features.

2 Likes

Hmm… But this would only teleport the part to this position. It wouldn’t actually keep it locked like that after the script has run.

1 Like

In that case, try tweening it or using CFrame:Lerp() so it doesn’t snap the part instantly to the destination.

Ok! So your saying put it in a loop so its always trying to tween back to the desired position.

1 Like

Why not use the prismatic constraint?

If you want the part to be able to rotate, but still have the ability to move on one axis then use the cylindrical constraint

4 Likes