This project is read-only.

Platform Game Kinetic Body SetLinearVelocity Issue

Jun 24, 2010 at 12:29 PM

Hi folks,

I'm having a problem or two with Box2D in a platform game I'm making. I've had a discussion with Erin Catto on the Box2D forums, and it's ended in him suggesting I contact the creator of the XNA port on what he seems to think is a bug. Any help is appreciated! Maybe someone else can spot what I'm doing wrong!


http://box2d.org/forum/viewtopic.php?f=3&t=5151

 

I know that it's a high possibility that it's not a bug, and that I'm doing something wrong, but hopefully you guys can help out. Note that the concern for there being a bug is that the bodies for these moving platforms are set to BodyType.Kinetic, and yet I'm still able to have them come off their original course, and that only seems to happen when the player body gets involved and is jumping around on top of them.

 

Thanks!

Jun 25, 2010 at 2:51 AM

I think you are showing a duplicate of this issue in Box2D:

http://code.google.com/p/box2d/issues/detail?id=110&can=1&q=status%3DDuplicate

 

This is now tracked as issue 107 on the Google code project for Box2D:

http://code.google.com/p/box2d/issues/detail?can=1&q=107&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&id=107

Jun 25, 2010 at 3:17 AM

Oh I read further and you ended up discussing a different issue (I was looking at the .swf).

Can you point us to a reduced repro?  A screenshot would also be helpful to get an idea of what you're talking about.

Jun 25, 2010 at 11:07 AM

Hey, thanks for the replies.

When I get home today I'll produce another couple of examples of the problem.

Bear in mind that all the blocks I have that move are of kinetic body type, and I'm of the opinion that those shouldn't be affected by a body (containing one polygon shaped created with SetAsBox) with a mass that is really quite low.

Even without showing the example, does it sound to you as though this should be the case? Kinetic body types are like static, except they can be moved with SetLinearVelocity (and probably able to do lots of other things). In most cases, the bodies in question in my game act like they should - they don't appear to budge, and they can happily push piles of BodyType.Dynamic boxes out of the way. It's just when I run along these boxes, it seems to confuse them.

I don't have the source with me, so I've made up a storyboard of sorts, explaining what happens:

http://yfrog.com/9ddiagramj

 

Jun 25, 2010 at 1:54 PM

I'm using kinematic bodies for moving platforms and I don't have any issues like that. I suspect the problem is with your 'passenger' system. I implemented something similar when I was (wrongly) using static bodies for platforms. A kinematic body should carry around anything sitting on it just fine without you having to do anything else. My suggestion, get rid of the 'passenger' system and see how it works.

Jun 25, 2010 at 2:14 PM

Thanks for the replies, folks.

As for the passenger system, I'll try turning it off again, but I think I tried that before. Besides, the passenger system is only adding to the player's force/impulse - it's when the player decides to apply its own force/impulse that the boxes start moving out of sync. If I have the player on the moving platforms (as a passenger), and even jump up and down, everything's fine.

Jun 26, 2010 at 12:50 PM

Box2D already did that when it solved the island. So, at best, it's redundant.

Jun 26, 2010 at 12:52 PM

Are you saying I should be using Islands to solve this problem I'm having?

Jun 29, 2010 at 7:57 AM

Logically any kinematic body should not be affected by forces or impulses.  You set the velocity yourself and the engine solves position for you and applies forces but doesn't receive them.

Assuming you have properly set up kinematic boxes they should plow through everything in their path and nothing should phase them.

In our latest port of r112 I noticed there were some fixes that related to the distinction of "non static" vs "dynamic only" and if some positioning code thought it should apply to "non static" it would also apply to kinematic incorrectly (in such a case it should really be "dynamic only") so those may be at play here.

I can try to code a reduced repro test case when I get a chance but for now you should file an issue in the "Issue Tracker" section of CodePlex and add all details that you have.