Collision event doesn’t work every time when the collision occurs

Software: Away3D 4.x

programmist, Newbie
Posted: 06 August 2012 11:49 AM   Total Posts: 13

I added event listener to detect when my balls collide. But this event doesn’t work properly. Why?

ballBodies[0].addEventListener(AWPEvent.COLLISION_ADDEDonCueCollided);

private function 
onCueCollided(event:AWPEvent):void
  {
   
var b:BilliardBall = (event.collisionObject as AWPRigidBody).m_userData as BilliardBall;
   
   if (
b)
   
{
    
if (b.getRigidBody().mass 0.0)
    
{
     
if (firstContact == null)
      
firstContact b;
     
     
    
}
    
    
   }
   
   
   
  } 
   

programmist, Newbie
Posted: 06 August 2012 11:51 AM   Total Posts: 13   [ # 1 ]

I need to know with what the cue ball collided firstly but it works every two times or even rarely

   

John Brookes, Moderator
Posted: 06 August 2012 10:20 PM   Total Posts: 732   [ # 2 ]

Have you enabled
physics.collisionCallbackOn = true;

what happens if you just trace out

event.collisionObject.skin.name

assuming its skinned and named.

   

programmist, Newbie
Posted: 08 August 2012 11:06 AM   Total Posts: 13   [ # 3 ]

Yes, of course I’ve enabled this option.
unfortunately I don’t use skinning

   

John Brookes, Moderator
Posted: 08 August 2012 02:16 PM   Total Posts: 732   [ # 4 ]

Point being, you need to find out what is happening inside the cuecollided.
What the collsionObjects are. Are you sure it can only be billardBall?

I seem to have lost my copy of billiard ball and thers not much to go on apart from no worky wink

   

programmist, Newbie
Posted: 09 August 2012 07:06 AM   Total Posts: 13   [ # 5 ]

No, it can’t only be a billiardBall because the cueBall is rolling on the table. If event occurs with the table then variable b will be null and nothing happens.
I removed the table and gravity, so the cueBall can only collide with billiardBalls, the problem is the same(

   

dtramer2, Newbie
Posted: 28 July 2013 04:10 AM   Total Posts: 16   [ # 6 ]

I’m suspecting this is a bug in awayphysics.  I think I know what the problem is here.  The same thing is happening for me.

It happens much more if you use a much higher step frequency (meaning the 3rd parameter to the away physics world step function is lower).

Some background:

The awayphysics collision callbacks are called from the awayphysics step function. 

As suggested here: http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers
the awayphysics step function iterates over all of the contact manifolds. 

The problem is that awayphysics doesn’t follow this additional advice from that link:

“This should be done during a simulation tick (substep) callback, because contacts might be added and removed during several substeps of a single stepSimulation call.”

So, what is happening is that if the collision occurs during one of those in between sub-steps, the collision callback won’t be called.

 

 

 

   

dtramer2, Newbie
Posted: 28 July 2013 05:40 AM   Total Posts: 16   [ # 7 ]

Just to be clear (regarding my post above):

If you don’t pass in a sufficiently low 3rd parameter (or if you don’t pass any 3rd parameter) to the step function, then you may never (or very infrequently) encounter this bug.

   

John Brookes, Moderator
Posted: 28 July 2013 01:01 PM   Total Posts: 732   [ # 8 ]

Just tried a basic drop ball test and yeah can confirm is an issue.
Post bug on Git

   

Yang Li, Administrator
Posted: 29 July 2013 02:08 AM   Total Posts: 80   [ # 9 ]

can you send your test code, I’m always not reproduce this bug.

   

dtramer2, Newbie
Posted: 29 July 2013 12:39 PM   Total Posts: 16   [ # 10 ]

Here is my call to step. 

private var lastTime:int
  
private function onEnterFrame(event:Event):void
  {
   
var newTime:int getTimer()
   if (
lastTime)
   
{
    _world
.step((newTime lastTime) / 1000.015500);
   
}
   lastTime 
newTime 
   

Yang Li, Administrator
Posted: 29 July 2013 01:27 PM   Total Posts: 80   [ # 11 ]

hi, I use this step parameter still not reproduce the bug, but I have changed collision detecting in the tick callback. you can update the latest swc.

   

John Brookes, Moderator
Posted: 29 July 2013 01:57 PM   Total Posts: 732   [ # 12 ]

That fixes it for me.

was using this to test.
https://gist.github.com/JohnBrookes/f12de24f2e6d907fe436

   

dtramer2, Newbie
Posted: 29 July 2013 10:41 PM   Total Posts: 16   [ # 13 ]

Fixed it for me as well.  Thanks.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X