Box2D Forums

It is currently Fri May 24, 2013 11:13 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Wed May 02, 2012 2:21 pm 
Offline

Joined: Mon Jan 23, 2012 9:51 am
Posts: 15
Hi guys,

I am making a 2D sidescroller that happens to have moving platforms. Thanks to your help I was able to implement them, but now I am facing another issue regarding them.

When the platform is moving downwards (it keeps moving up and down) and the player lands on it, they never actually collide (I put a breakpoint inside beginContact). The player keeps on accelerating, but his position is not updated accordingly as he accompanies the platform without touching it. Finally, the collision only happens when the platform starts to move up.

Then, I tried to set the players body bullet flag to true, and everything started to work as expected. Could someone explain to me how did this happen?


Top
 Profile  
 
PostPosted: Thu May 03, 2012 3:20 am 
Offline

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
Are the moving platforms static or kinematic? If they're static, make them kinematic.

If they're already kinematic, are you using the SetLinearVelocity() function to move them or are you setting the positions directly? If you're setting the positions directly, use SetLinearVelocity instead.


Top
 Profile  
 
PostPosted: Thu May 03, 2012 10:44 am 
Offline

Joined: Mon Jan 23, 2012 9:51 am
Posts: 15
Thanks for the answer!

They are Kinematic and I use setLinearVelocity to move them already =)


Top
 Profile  
 
PostPosted: Sun May 06, 2012 6:12 pm 
Offline

Joined: Mon Jun 08, 2009 12:21 pm
Posts: 353
Hm, this is strange. What version of the engine are you using? There's a chance this might be a bug with Box2D


Top
 Profile  
 
PostPosted: Mon May 07, 2012 1:03 pm 
Offline

Joined: Mon Jan 23, 2012 9:51 am
Posts: 15
Thanks for the answer =)

I am using the latest version available at the google code page. I found it really weird too, I will try to reproduce it on the testbed and send it back to you. Where can I post it?


Top
 Profile  
 
PostPosted: Sat May 12, 2012 6:20 am 
Offline

Joined: Mon Jan 23, 2012 9:51 am
Posts: 15
Finally was able to build the testbed and implement the test I wanted to show. It is very simple, ask the testbed to draw the contact points and you will see there are none. Also, I noticed that if I turn off Continuous Collision, contact points will appear.

So, here is the test:

Code:
package org.jbox2d.testbed.tests;

import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.testbed.framework.TestbedTest;

public class MovingPlatformTeste extends TestbedTest {

   @Override
   public void initTest(boolean argDeserialized) {
        setTitle("Moving Platform Test");
      
        getWorld().setGravity(new Vec2(0, -100));
      
        PolygonShape polygonShape = new PolygonShape();
        polygonShape.setAsBox(10, 1);
       
        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyType.KINEMATIC;
        bodyDef.position.set(0, 20);
        bodyDef.allowSleep = false;
        Body body = getWorld().createBody(bodyDef);
        body.createFixture(polygonShape, 5.0f);
        body.setLinearVelocity(new Vec2 (0.0f, -10.0f));
       
        polygonShape = new PolygonShape ();
        polygonShape.setAsBox(1, 1);
       
        bodyDef = new BodyDef ();
        bodyDef.type = BodyType.DYNAMIC;
        bodyDef.position.set(0, 100);
        bodyDef.allowSleep = false;
        body = getWorld().createBody(bodyDef);
        body.createFixture(polygonShape, 5.0f);
   }

   @Override
   public String getTestName() {
      return "Moving Platform Test";
   }

}



Top
 Profile  
 
PostPosted: Wed May 16, 2012 2:16 am 
Offline

Joined: Mon Jun 08, 2009 12:21 pm
Posts: 353
Cool, I'll take a look this weekend or next week


Top
 Profile  
 
PostPosted: Sun May 20, 2012 12:24 pm 
Offline

Joined: Fri Oct 07, 2011 9:39 am
Posts: 21
Hey, I would like to ask you something, sorry for offtopic, have you managed to 'sticky' your player to the platform while its moving?


Top
 Profile  
 
PostPosted: Tue May 22, 2012 12:46 pm 
Offline

Joined: Mon Jan 23, 2012 9:51 am
Posts: 15
Yes. Basically what I do is:

In the begin contact listener, if the character is touching a platform, I keep a reference of that platform and add the platform speed to the player's speed.

In the end contact listener, I just make the platfomr reference null.


Top
 Profile  
 
PostPosted: Wed Jul 18, 2012 12:25 pm 
Offline

Joined: Mon Jan 23, 2012 9:51 am
Posts: 15
Has this issue been solved?


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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