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
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.
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
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.
Why not attach the platform with a 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.
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.