I have been developing a 2d game recently.
the game allow you throw a block.
but I have a problem that some times collision will cause it move on z axis and out of the map
I try to use plane constraint to fix it but it will stuck at wall
I have seen a similar suitation like mine Need help locking only z axis of a part
I followed the solution but seems like it’s not work now.
probably because bodygyro and bodyposition was deprecated?
local part = script.Parent
local initialZ = part.Position.Z
local delay = .1 -- How fast should the script check if the Z axis changed
while true do
local posZ = part.Position.Z
if posZ ~= initialZ then
local posX = part.Position.X
local posY = part.Position.Y
part.Position = Vector3.new(posX, posY, initialZ)
end
wait(delay)
end
It almost work!
use while true cause a extreme lag
so I use Heartbeat as a alternative.
the result has 3 problem
1.cause a weird collsion physic
I use the method in this thread to limit its Orientation
So the problem now is fix How to lock rotation of a part?