lyc6512
(lyc6512)
August 24, 2022, 4:25am
#1
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!
3 Likes
adamik98
(adamik98)
August 24, 2022, 9:51am
#2
u could make it so it checks if z axis is changed it just changes it back
1 Like
adamik98
(adamik98)
August 24, 2022, 9:52am
#3
i believe something like this should work
local ZPosition = partdirectory.Position.Z
partdirectory.Position:GetPropertyChangedSignal("Z"):Connect(function()
partdirectory.Position.Z = ZPosition
end)
if it doesn’t i can change it
5uphi
(5uphi)
August 24, 2022, 10:36am
#4
you want to update the position after every physics simulation so we would use heartbeat
local runService = game:GetService("RunService")
part = ...
runService.Heartbeat:Connect(function(deltaTime)
part.Position = Vector3.new(part.Position.X, part.Position.Y, 0)
end)
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)
end
wait(delay)
end
The script should be located inside the part.
lyc6512
(lyc6512)
August 24, 2022, 2:21pm
#6
I don’t know how to modift your script,
“part:GetPropertyChangedSignal(“Z”)”
this line causes two problem
adamik98
(adamik98)
August 24, 2022, 2:24pm
#7
prob cuz u forgot part.Position and Z is not a valid property of part itslef
lyc6512
(lyc6512)
August 24, 2022, 3:20pm
#8
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!
lyc6512
(lyc6512)
August 24, 2022, 3:22pm
#9
Thanks for the information! I’ll try it.
adamik98
(adamik98)
August 24, 2022, 7:20pm
#10
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
lyc6512
(lyc6512)
August 25, 2022, 2:09am
#11
Yeah so I never use it. Render Step and Heartbeat are more reliable.
adamik98
(adamik98)
August 25, 2022, 6:13am
#12
i agree i only use while wait when i want loops to actualy wake a second or something not to repeat rlly fast
WxxMayN
(WxxMayN)
December 26, 2023, 1:04pm
#13
Use a part only collide box to block them.