Chipmunk Physics and character moving

Chipmunk Physics and character moving
0

Hello. I am developing my first platformer game and have problem with character moving logic using Chipmunk.

Please help me :slight_smile:

I have buttons “left” and “right” and I need character move only if button is pressed. Moreover if character impact to the barrier and jump after this, character should continue moving(above the barrier) because “right” button is still pressed. I mean constant moving if button is pressed and path is clear.

How can I implement this moving?

PS I have tried many ways but every has some problems.

Can you Tell usw your not working ways?

Hello, I found solution recently, after I created this topic :slight_smile:
Wrong ways were:

  • set velocity without any conditions: character partially enter into the walls.
  • move character via impulses: moving was’t with constatn velocity, it was noticeable
  • move via forces: character couldn’t start or change direciton fast
  • some combinations of these variants…

Solution I found:
I store active collisions with walls in character’s object(I use “normal” member of contact structure to detect contact direction).
Then in update() method I update velocity only if there is no wall in front of moving direction(for example, if “left” button is pressed and there is no contact with wall at left), otherwise I do nothing(physics engine works).

1 Like