Listen for RigidBody movement finished

Software: Away3D 4.x

Freon, Newbie
Posted: 07 August 2012 05:17 PM   Total Posts: 13

Sorry if this has been asked before but i’s kinda hard to now what to search for.

I have 1 dice inside a “box” with 6 walls and then throw the dice which bounces around and eventually lands (the time the dice rolls can change).
What is the best way to check when that rolling is done?

I have tried AWPCollisionEvent.COLLISION_ADDED with a timer. But that fires even when the dice is just lying still on the floor.

   

Richard Olsson, Administrator
Posted: 08 August 2012 08:11 AM   Total Posts: 1192   [ # 1 ]

I would suggest you just check the dice’s speed every frame, and when it’s below some threshold you treat it as if it has stopped.

Every frame, take the position of the dice, subtract it from the previous position, check the length of the resulting vector (which is the speed) and then store the current vector for the next frame.

var velocity Vector3D myDice.position.sub(_prevPosition);
if (
velocity.length 1{
  
// Dice stopped
}
 _prevPositi 

For the sake of readability the above code isn’t quite as optimized as it could be (by avoiding to allocate a new vector, as well as preventing this from entire chunk from being repeated at all once the dice has already stopped.

   

Freon, Newbie
Posted: 08 August 2012 08:22 AM   Total Posts: 13   [ # 2 ]

That’s clever - thank you.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X