Box2D Forums

It is currently Sat May 18, 2013 4:31 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Aug 17, 2012 8:27 am 
Offline

Joined: Fri Aug 17, 2012 8:04 am
Posts: 2
I have a decently working platformer physics, except for one little problem. The player can't move into narrow openings when falling/jumping.
To illustrate the problem, here's a picture:

Image

Logically, it makes sense that gravity overpowers the smaller force applied by player, but platformer physics don't strictly follow real world rules:)
I tried using a rectangle with "clipped ears" instead of a regular one, but it didn't work.

Any thoughts how to deal with this? The solution doesn't have to be clean. Any hack will do:)


Top
 Profile  
 
PostPosted: Fri Aug 17, 2012 5:32 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
Here's one way you might be able to do it... have a fixture on the player body which is only activated when the player is trying to move right, as shown by the red rectangle in this image.
Attachment:
stepontoledge.png
stepontoledge.png [ 17.18 KiB | Viewed 473 times ]

The collision flags for this fixture would be set so that it only interacts with other special fixtures like the green rectangle in the image, in places where the player should be able to catch hold of a ledge.

In BeginContact or PreSolve, any contacts between these two fixtures would be disabled unless the player was pressing 'right' - that would solve the issue in your picture...

In practice though it's not so simple, because what about when the player is jumping upwards to the ledge, and therefore approaches it from the bottom moving upwards? The contact between the two fixtures would be active and the player would never be able to touch the wall at all. Essentially you now have the 'one-way platform' problem to deal with :D

Depending on how you arrange those fixtures you might be able to simply look at the vertical velocity of the player and disable the contacts if he is moving upwards.

Another problem is that you would then have to go through your world and place the green fixtures all over the place... it would be good if something more clever could be done to solve the problem with only fixtures on the player body.


Top
 Profile  
 
PostPosted: Sat Aug 18, 2012 12:40 am 
Offline

Joined: Tue Sep 25, 2007 2:22 pm
Posts: 482
More/smaller timesteps would probably help.


Top
 Profile  
 
PostPosted: Sat Aug 18, 2012 1:09 am 
Offline

Joined: Fri Aug 17, 2012 8:04 am
Posts: 2
irresistible force: Perfect, thanks for your inspiration, the "conditional fixture" is the key.

This is what I came up with:
Image

- the right rectangle is only active if the player is holding the right arrow
- it collides only with black (horizontal) edges, only in one direction.

For instance the ground edges would only collide with the helper rectangle only when falling. The ceiling edges would collide only when jumping/ascending.
The manual says this can be achieved in pre-solve event by calling b2Contact::SetEnabled(false)

pTymN: nope, the contact with the platform is actually made even with current settings, but disregarded, since the falling speed is greater than player's moving speed


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group