Make unanchored parts not falling on Z Axis

Hey there, I’d like to know if it is possible to make unanchored parts falling and changing of position on the X Axis, and on the Y Axis but not on the Z Axis.

I am making a 2D Platformer, but I have some unanchored parts with some constraints like rods, springs, … But the parts are moving on the Z Axis that is not what I want.

Is there any way to modify that? Can I use some constraints to do so?

Like, a constraint that make the unanchored part have the same Z Axis position than another part, that is anchored?

I tried loads of things but I don’t really want to use scripts with stuff like

-Invisible walls

while true do
    --code
end

--Or

game:GetService("RunService").RenderStepped:Connect(function()
    --code
end)

--Or other stuff that may be not good for the server.

Please, I tried loads of stuff to do so but nothing was successful. Please help me :frowning:

EDIT: I don’t want the blue part to move on the Z Axis, I want it to move on the left, on the right, up and down but not forward and backward. ( https://gyazo.com/22b347ab354329800fca12026af0146a )

Yes! You can constantly set the Z Position of the part to 0 by detecting a change in the property!

local parts = workspace:WaitForChild("FallingParts") --folder where parts go

parts.ChildAdded:connect(function(child)
    child:GetPropertyChangedSignal("Position"):connect(function(val)
        child.Position = Vector3.new(child.Position.X, child.Position.Y, 0)
    end)
end)

NOTE: This may be choppy its just an example code.

This may cause some lags for the server, and may not be optimized with constraint .-.

Can the player only move forwards in backwords. If so, the z position of the part should subsequently never change.

Yea, they can only go left, right, up and down. W and S are useless

My bad, i meant to say to put this in a local-script having it be ran locally through the player as the physics are better derived from the client side of things, unless you are needing to do it for a server sided effect instead of just a random client effect!

But if I do my game as a multiplayer platform too, will this get some impacts? I guess yes, like these are not really falling parts, these are kind of platforms connected to the roof with a rope constraint
I just don’t want the platform to move backward and forward. And I can’t use tweening as the movements are not predictable

Then yes I would personally use a local-script as you are just changing the position of the part of something that is attached using a rope constraint! It will be ran across all players as its in a local-script and not needed for server-sided validation.

You can use a BodyPosition on the Part, with the Z position set to the value you want, and the Force having only a very high Z value, e.g. 0, 0, math.huge

1 Like

Like, this bodyPosition will force the part to stay in its X and Y positions, even if it is moving, but on the Z Axis, it’ll stay locked on a value I placed…?

Yes, it will constrain the object to a plane with constant Z value, and have no effect on the X and Y direction movement. This is something the legacy BodyPosition can do that I don’t think AlignPosition supports yet.

I’m not sure if this would work but you can try with math.clamp

What is the utility of math.clamp()?

I found by myself though

But can this “disturb” the movement of the unanchored part basically?

Why not attach the platform with a PrismaticConstraint?
https://developer.roblox.com/en-us/api-reference/class/PrismaticConstraint
It only works in one axis, and you can change the speed it travels as well as put the ActuatorType as Servo so you can control where the Platform travels from and to.

EDIT: I don’t want the blue part to move on the Z Axis, I want it to move on the left, on the right, up and down but not forward and backward. ( https://gyazo.com/22b347ab354329800fca12026af0146a )

Does this correspond?

A PrismaticConstrait constrains the part to move along a line (1 axis), and without any rotation. This is not what he wants.

1 Like

You can set PrismaticConstraints to move in any straight line you want. Typically if you add one in Studio it will point in the direction of the side of the Part you face it in. An Attachment will be added to that Part as well, but you can use the Rotate tool on the Attachment to point it wherever you’d like.
You could set up an Anchored Part to have one PrismaticConstraint for the X axis and connect it to an Unanchored Part, then have another PrismaticConstraint attached to that Part so it’ll travel along the Y axis.

Yes, but can it go up and down, and left to right? Like I don’t really see how you make rotate the unanchored part then -

Do you have any other solution about that then?