Jumping from non static platforms

Hello!

I am trying to make a simple platformer, but I have a small problem with jumping.

The jumping works fine on static platforms, but it seems to become unstable on non static platforms.

I have created a "rope bridge" - when the player stands on the rope bridge the jumping seems to become buggy.

Apparently the contacts between the player and the bridge are not always registered by the b2ContactListener.

I have tried different workarounds, but the problem persists.

If this is an issue that has already been covered on the forums I apologize.

Here is a link to the swf file. Use arrow keys. The rope bridge causing the problem is located to the right.

http://megaswf.com/view/007309eafc3863e240c72ae41d032344.html


Thanks

Simon
Well either I'm a complete retard but I cannot even reach your bridge to be honest 😆

also it would be nice if you could show us how you are making your character jump right now in order to help you.
Stryke wrote:
Well either I'm a complete retard but I cannot even reach your bridge to be honest 😆


me too 😕

ok, but back to topic. in the ground/air detection you can add a little delay, when groundcontact is lost. so that you are "physically" in the air, but for your game logik jumping will still work. this often fixes problems regarding small gaps or little jumps on moving objects.
I have the same problem as the OP, though im not sure if they are caused by the same things.
I dont have a rope bridge in my prototype, but I do have a seesaw and when the seesaw has one side down and the other up, the player a lot of times wont beable to jump because it isnt registering the contact. I was thinking this was because only the corner of the players bounding box is hitting the seesaw so theres a gap directly below him everywhere except that corner.

Does that sound like that same problem OP? Because I would love to know how to fix it 🙂

Sorry if this has nothing related to your problem!
@Azh321 a contact would still register at the corner of a box. if your hero is held up by something there is a contact. although from your comment it sounds like you are checking for something directly below the hero, rather than looking at the direction of the impulse of the contact. its possible that simDK is also not checking impulse of contact.
Hello everybody and thanks for the fast replies

Stryke - I have uploaded a new version of the swf file. There should be no problems reaching the rope bridge in this updated version 🙂

http://megaswf.com/view/747face972e7cc600c15d040d739e1f5.html

As to my jump functionality is pretty standard I guess. The ContactListener simply checks if the player is on/off ground and turns a jumping boolean to true/false correspondingly.

Azh321 – I'm not sure if the cause is the same, but our problems sounds very similar.

Astrocreep – Would you suggest using a timer for the delay?

Sketchbookgames – As far as I know, I am not checking the impulse of the contact. It is actually the first time I have come across that concept. Is it a topic that has already been covered on the forums or in the manual?

A final question – could the problem possibly be caused by the gaps between the different elements of the rope bridge, instead of by the fact that the elements are not static?

Thanks again

Simon
this is the part you must elaborate on for us to help you
Quote:
checks if the player is on/off ground


i may be able to find an example of impulse for you, easier if i know:
what version are you using?
2.01 Box2DFlash
2.1 Box2DFlash
2.1 Alchemy port
2.1 Alchemy port with WCK
I use the b2ContactListener to check if the player is on/off ground, like so:
Code:
//Jumping on
override public function Add(point:b2ContactPoint):void{
if (point.shape1.GetBody().GetUserData() is MovingPlatform && point.shape2.GetBody().GetUserData() is SensorTest) {
SensorTest(point.shape2.GetBody().GetUserData()).onJumpFlag();   
}else if (point.shape1.GetBody().GetUserData() is SensorTest && point.shape2.GetBody().GetUserData() is MovingPlatform) {
SensorTest(point.shape2.GetBody().GetUserData()).onJumpFlag();
}
}
//Jumping off
override public function Remove(point:b2ContactPoint):void{
if (point.shape1.GetBody().GetUserData() is MovingPlatform && point.shape2.GetBody().GetUserData() is SensorTest ) {
SensorTest(point.shape2.GetBody().GetUserData()).offJumpFlag();
}else if (point.shape1.GetBody().GetUserData() is SensorTest && point.shape2.GetBody().GetUserData() is MovingPlatform) {
SensorTest(point.shape2.GetBody().GetUserData()).offJumpFlag();   
}
}

I am using version 2.1 Box2DFlash

I tested the rope brigde with the different elements set to static.
http://megaswf.com/view/64f844ff37d644c ... 28d55.html

It seems that the b2ContactListener is not triggered when “sliding” across the small gaps between one element to the next.


Thanks.

Simon
Quote:
It seems that the b2ContactListener is not triggered when “sliding” across the small gaps between one element to the next.

not true.

anyway looking at your code, it seems you set OnGround = true on contact with "ground", and set OnGround = false on removed contact with "ground"

which makes me 99% sure of your problem.

imagine your user standing on 2 septate planks on a bridge. (P1 and P2)
then think of the possible order of events.

P1 Add//true
P1 Remove//false
P2 Add//true
P2 Remove//false
that would be ideal, and is generally what happens elsewhere in your game.

however your bridge has a chance of.

//THIS DEMONSTRATES YOUR CURRENT PROBLEM
P1 Add//true
P2 Add//true
P1 Remove//false
(technically still in contact with P2, but your boolean is now false.)


you need to manage multiple contacts better.

Method 1:
one way is to add your qualifying contacts to an array. and if there are any still in the array (length>0), you are on the ground.
another way (slightly less reliable, but would probably work in this case) is to count your qualifying contacts in an integer. if the count is >0 you are OnGround, ==0 not OnGround, <0 something broke use array method instead. (also if it doesn't return to 0 while not grounded, there is a problem, and the array method would be better.)

//0 //false
P1 Add//1 // true
P2 Add//2 // true
P1 Remove//1 //true
P2 Remove//0 //false

Method 2:
if you run into problems getting BeginContact / EndContact listeners to line up and settle back at zero, another method could be: PreSolve or PostSolve should generate calls for continuous contacts. in which case you set OnGround = false each frame, and to true if there is any qualifying PreSolve or PostSolve contact. be sure that your PreSolve/PostSolve calculations happen between setting to false and your KeyListener to jump.


enjoy your multiple contacts.
and rest assured that box2d does fire all contacts. if you are un-sure you may trace when each contact is fired to see it. that would have shown your problem too if studied closely.
also if you were interested in impulse method.
http://box2d.org/forum/viewtopic.php?f=8&t=5057

(frnk found that post and linked to it in another recent post)

the impulse method is used to make sure your contact is pushing upward on your hero (since your hero has a separate Foot shape, its not entirely necessary for your current situation.)

Original thread: https://box2d.org/forum/viewtopic.php?t=5054