Box2D Forums

It is currently Thu May 23, 2013 3:04 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Mar 14, 2012 8:17 am 
Offline

Joined: Wed Mar 14, 2012 7:55 am
Posts: 1
I have a world set up with edges corresponding to the edges of the screen on a phone. The boundaries are a closed rectangle of dimensions 320x480 where (0,0) is the bottom left corner.

I have an enemy that is a ball that I want to move from off screen to on screen in a smooth motion. However, I want to maintain accurate collisions with the enemies that are already on screen. For example, when the enemy ball is transitioning to on screen and it is only half way on screen, I want the enemies that are already present to bounce off of it as if it were a half circle.

What I am doing now is to create a static body at some point off screen (say (-100, 100)) and on my update I increment the x position of the ball until it is at some point on screen (say (100, 100))

But what happens is the physics engine recognizes the ball is on an edge and "squeezes" the ball into the physics world. Basically, I just want this body to ignore walls for a period of time until it is fully on screen and then I want it to adhere to the edges as it normally would.

I hope this makes sense. If it helps, think of a pin ball game where you pull a lever back and launch a ball into the game.


Top
 Profile  
 
PostPosted: Wed Mar 14, 2012 10:38 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
Are you using a contact listener? You could check in PreSolve whether the two fixtures are the wall and the incoming ball, and disable the contact if the ball has not yet entered the screen.


Top
 Profile  
 
PostPosted: Thu Mar 22, 2012 9:48 am 
Offline

Joined: Thu Mar 22, 2012 9:15 am
Posts: 2
Use a contact listener to pre-solve.

void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
Test::PreSolve(contact, oldManifold);

b2Fixture* fixtureA = contact->GetFixtureA();
b2Fixture* fixtureB = contact->GetFixtureB();

b2Vec2 position = ball->GetBody()->GetPosition();

// If coming from outside of screen (add your code here)
{
contact->SetEnabled(false);
}
}

Best Regards,
Gabriel Lim


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Exabot [Bot] and 7 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