79249174

Date: 2024-12-03 21:10:33
Score: 0.5
Natty:
Report link

You could attach a boolean to the Player that determines whether the Player is "on a moving platform" or not. Maybe you could call it "onMovePlatform".

You could use PyMunk's CollisionHandler class (https://www.pymunk.org/en/latest/pymunk.html#pymunk.CollisionHandler) to detect whether or not the player is on a MovePlatform object, or in this case, if the Player is "colliding" with the MovePlatform object. So when the Player "collides" with the MovePlatform, you can set: "onMovePlatform = True"

If the program sees that "onMovePlatform == True", you can make it so that every time the MovePlatform's position changes, you use the same change to the MovePlatform and apply it to the Player position as well. Like if MovePlatform is moving 5 to the right every frame, you add 5 to the right for the Player as well. Same applies to the other direction(s), and vice versa.

Then when you press Space to jump, you can automatically set onMovePlatform = false since you can assume that since you are now in mid air, you are no longer in contact with the MovePlatform object, and since the boolean is now set to false, it no longer applies the transformation to the player's position.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Jerome Goyena