bug in physics plugin on jumping ?
Shri

Gio,

I was adding jumping to the stickman demo. I noticed something funny that I hadn't caught before. If you run the demo, and hit the up arrow to jump, it seems to jump correctly only every other time. If you run the app, the stickman is standing idle. Hit the up arrow and he jumps full height. Wait until he lands and settles, then hit the up arrow again, and he only jumps a tiny bit. Then you can repeat (big jump, little jump). Not sure if this is something I am doing wrong or if it is in the plugin. Both times, I am calling the same code and the y impulse vector is the same.

On another note, sometimes the collidingWith object contains all false, even when the stickman is standing idle on the floor. This bug is hard to recreate, but seems to happen at the chain vertices. This causes the stickman to freeze, as he can't move or jump because it thinks it is not touching anything. This may be a box2d bug (I think I saw something on this a while ago), and like I said, it is hard to recreate, but just fyi.

I have attached all the code here as a zip file.

cheers - shri

 

All 3 Comments
Gio

Hey Shri

We've been working on making a physics-based platformer with wade physics - this is something that will eventually become part of Wade, though not immediately, probably for version 4.0. 

The way we deal with jumps is probably much simpler, i.e. we don't use joints and sensors, we simply apply an impulse to a body. I don't really know the details as foxcode is working on it, but this seems to work every single time. I think if there was a bug at such a fundamental level, we would have noticed it by now, so it's a bit unlikely.

Could it be that, when it fails, it's because of some collision that's getting in the way and reducing the impulse?

Shri

Gio,

Thanks for the info. I am using a sensor to determine whether the stickman is in contact with something below, and then just using applyImpulse for the jumping (no joints, only standard released stuff). I set up a yImpulse vector variable in the robo.js file as {x:0,y:-1} and then used this variable when calling applyImpulse(). It would work fine on the first time, but then on the second, the variable was being reset to {x:0,y:1} (Jumping down) and on the next time, it would return to the original value {x:0, y:-1}, thus the working every other time thing. I was not resetting this variable anywhare in the code ? so I'm not sure why that was happening. Should I be cloning the objects before making the physics call ? Anyway I defined it as a local variable directly before the applyImpulse() call and it all works fine now.

On another note, regarding the collidingWith stuff, when the stickman is in the walking or running state, and it receives a jump command, I first check to see if the stickman is on the ground. by going through the collidingWith object to see if any are true. If none are true, then the stickman is not grounded. and so can't jump. This is necessary, because when walking/running over uneven terrain, the stickman can bounce through the air briefly. Anyway,  if I received the "can't walk or can't run because not grounded message, I decided to dump the collidingWith and sure enough, all fields are false, but it  looks like sensor on the stickman is in contact with the ground.?  So, I'm not sure if the collidingWith is not being updated correctly, or if I need to introduce a delay or what ? If you run the stickman jump from my website with the console open, you should see what I am talking about.

cheers - shri

Gio

I finally had a chance to look at this properly, and I think you're absolutely right - when calling PhysicsObject.applyImpulse(), the impulse vector that you pass to it is modified inside the funciton. It should be cloned internally first, of course.

It will be fixed in the next version of WADE, thanks for letting us know about the problem.

Post a reply
Add Attachment
Submit Reply
Login to Reply