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?
I would appreciate your help!
u could make it so it checks if z axis is changed it just changes it back
i believe something like this should work
local ZPosition = partdirectory.Position.Z
partdirectory.Position.Z = ZPosition
if it doesn’t i can change it
you want to update the position after every physics simulation so we would use heartbeat
local runService = game:GetService("RunService")
part = ...
part.Position = Vector3.new(part.Position.X, part.Position.Y, 0)
You could try using this:
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)
The script should be located inside the part.
I don’t know how to modift your script,
this line causes two problem
prob cuz u forgot part.Position and Z is not a valid property of part itslef
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?
but it cause a new error
Maximum event re-entrancy depth exceeded for Instance.Changed (x1110) - Studio
2.break the block welding
I think I can use some Constraint like AlignPosition to fix it?
- When player touch the block, it shake rapidly.
don’t sure which thing cause the issue.
thanks for your reply.
I was frustated about that Roblox lack of 2d physic.
Finally I see a ray of hope!
Thanks for the information! I’ll try it.
never use while true without adding atleast wait() somewhere in there due to what i believe is while true actualy fires more rapidly than heartbeat
Yeah so I never use it. Render Step and Heartbeat are more reliable.
i agree i only use while wait when i want loops to actualy wake a second or something not to repeat rlly fast
Use a part only collide box to block them.