I have a platform which I put a box on. I then click to have the platform move upwards, however, when the platform returns downwards it leaves the box floating.
if i use the player to click on the side of the box to pull it, the box will fall due to gravity.
How do i resolve this?
Well itâs hard to say exactly without knowing anything about your box or its code, but since you said it falls once the player hits it it sounds like your only applying physics (ie gravity) on collision.
Yeah thatâs great. Right off i see youâre adding rhe gravity if its not on the platform, but itâ all commented out. Iâm guessing you did that because it wasnât working as you expected? Probably because on_platform_body isnât getting set back to false.
So if i disable the top code I get the floating effect of the box. If it is enabled., it lets the platform drop a few pixels which are very obvious but lands on the platform and goes back down.
This the out put of the print statements.
on_platform_body entered: true â fisttime box is pulled onto the platform
on_platform_body exited: false â box floats
on_platform_body entered: true â box drops and lands on platform
Not sure what its stuck on or why it should not just stay on the platform becoing TRUE till the player moves it again.
Cheers for sticking with me on this!
OK so I ended up trying it out because that didnât seem to make sense, and I think I see what youâre talking about. Itâs caused by you box going into sleep mode because itâs stopped moving (to save CPU) You can turn this off under Deactivation\can sleep. I also found that gravityâs automatically added to RigidBody2Dâs so you shouldnât need that.
Tried what you said. Worked. I did end up getting things working by adding a small script to the platform and calulating the velocity of the platform. Passed this through to the box and also worked.
Is it wise to turn of the sleep function on objects?
If itâs just one box is probably not a big deal, but yeah you wouldnât want to generally just turn it off. That was more to test it. Youâd want to use the is_sleeping() and set_sleeping() methods.