Box2D Forums

It is currently Sun May 19, 2013 8:14 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: wck ContactList
PostPosted: Mon Sep 27, 2010 2:00 pm 
Offline

Joined: Tue Feb 24, 2009 4:10 pm
Posts: 564
Location: Michigan
hero extends shapes.circle

i create a new ContactList like this

Code:
contacts = new ContactList();
contacts.listenTo(this);



i have tried
Code:
contacts.update();

and
Code:
contacts.clean();


before and after jumping. still seems to act odd.

so i told it to flip scaleX of all bodies on the contact list with each jump (each wall is a seperate shapes.Box body.)
please notice that there are often many walls being flipped that the hero is no where near in contact with.

am i doing something wrong or is ContactList broken in some way?

i tried the dot manifold system that was in the demo boxMan, and currently have dumbed it down to isGround (which each horizontal wall is set to true) and then i noticed there were walls in my contact list that im not near.
Code:
private function canJump():Boolean{
   if(getTimer() - jumpDelayCount < jumpDelay) return false;
   
   var manifold:b2WorldManifold = null;
   var dot:Number = 9.5;
   var isGrounded:Boolean = false;
   
   if(!contacts.isEmpty()) {
      contacts.forEach(function(keys:Array, c:ContactEvent) {
         var otherShape:* = c.other.m_userData;
         var otherBody:* = otherShape.body;
         
         if(otherBody.isGround){
            isGrounded = true
         }
         otherBody.scaleX *= -1
         
      });
   }
   return isGrounded;
}


i will probably switch back to the dot manifold system which checks the direction of the contact after i get the contact list issue resolved. currently I'm not able to make heads or tails of this.

thanks for your time, hope I'm just missing something silly.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Mon Sep 27, 2010 2:58 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
Make sure you've set both reportBeginContact and reportEndContact:
Code:
reportBeginContact = true;
reportEndContact = true;

That's the first thing I can think of that would result in false contacts.

contacts.clean() should be called EVERY timestep, once you're done processing contracts. It'll remove contacts that have ended that step. The reason you call it AFTER processing contracts, is you may want to process contacts created / destroyed in the same step (bullets, etc.). If you don't care about those you can just call contacts.clear() whenever.

You shouldn't need to call contacts.update(). There are certain cases where contact info is "stale" after a timestep and this will make sure the contacts are synced up with what you see visually.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Mon Sep 27, 2010 3:59 pm 
Offline

Joined: Tue Feb 24, 2009 4:10 pm
Posts: 564
Location: Michigan
can you recommend what code to use to make this call every time step?
would i override something in the bodyshape or in the main class that extends WCK
currently my code doesn't touch the time steps from what i see.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Mon Sep 27, 2010 4:00 pm 
Offline

Joined: Tue Feb 24, 2009 4:10 pm
Posts: 564
Location: Michigan
begining and end contacts events seem to have helps a ton. and i call contacts.clean() on EnterFrame. until i know more about how to do it directly on the time steps. seems to be solved. thanks a ton!


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Mon Sep 27, 2010 4:34 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
The BoxMan class sets up a timestep listener in its create() function:

Code:
listenWhileVisible(world, StepEvent.STEP, parseInput, false, 10);


listenWhileVisible is just a wrapper for addEventListener. So it's calling the "parseInput" method every timestep. Within that function is:

Code:
contacts.clean();


The STEP event is dispatched from the world, within an ENTER_FRAME listener, so essentially you are doing the same thing. The only difference is the STEP event wont be dispatched if the world is paused.

So I'm guessing you just forgot to set reportEndContact; thus the extra contacts. If you need any more info you have my IM.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Tue Sep 28, 2010 11:12 am 
Offline

Joined: Tue Feb 24, 2009 4:10 pm
Posts: 564
Location: Michigan
perfect. Thank you.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Thu Dec 02, 2010 3:34 pm 
Offline

Joined: Tue Feb 24, 2009 4:10 pm
Posts: 564
Location: Michigan
can you think of a reason this would break when using shapes inside a BodyShape?

i seem to get
contacts.isEmpty(): false
contacts.num: 0


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Thu Dec 02, 2010 4:14 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
A quick search reveals that "num" variable isn't even being used. I must've used it at some point but forgot to remove it. I'll take it out.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Fri Dec 03, 2010 3:42 pm 
Offline

Joined: Tue Feb 24, 2009 4:10 pm
Posts: 564
Location: Michigan
it also seems that the forEach doesn't trigger, meaning that there are no contacts, despite isEmpty being false most of the time (even when in the air)

it worked well when my hero was the circle, but now that my hero contains a circle and a rectangle it doesn't work well, perhaps im missing something that is shape only and not body related.


Top
 Profile  
 
 Post subject: Re: wck ContactList
PostPosted: Fri Dec 03, 2010 5:31 pm 
Offline

Joined: Mon Apr 07, 2008 3:06 am
Posts: 99
I seem to be having a similar problem with ContactList data. My character has sensors to his left and right, so that when the player wants to grab hold of an object, whatever one of those sensors is touching gets attached to the player with a joint. This is working fine, except that for some reason, the object in those sensors' ContactLists is sometimes nowhere near the player.

I am already calling contactList.clean(); on the world StepEvent.STEP


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 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