How would i prevent a part from moving to the sides?

so im working on a “2D” game and i want to prevent players from falling out of the map


so i basically just want to lock one position axis of the part, but i have no idea if its even possible

i could technically just add invisible walls but i feel like thats not really a perfect solution

any help appreciated!

1 Like
local Part = --path to the part

local BP = Instance.new("BodyPosition", Part)
BP.MaxForce = Vector3.new(0, 0, math.huge)
BP.Position= Vector3.new(0, 0, Part.Position.Z)
BP.D = 0

i know that BodyPosition is depricated but i couldnt think of an another solution

1 Like

yeah that kinda works but it makes everything shaky
ill try playing around with it

1 Like

yeah also setting the d value to 10000 fixed the shaking issue. thanks!

1 Like