Find out what face is facing upwards on a dice

Software: Away3D 4.x

sk, Newbie
Posted: 09 April 2013 08:55 AM   Total Posts: 8

I’m trying to create a dice. I will use the physics engine to roll the dice and my problem is how to find out what number the user actually got?

Each face of a cube will have a texture representing 1-6. My idea is that I could loop all the faces of the dice and try to find out what face is facing upwards after rolling it.

Not sure if this is a good method or if there is a simpler solution?
If this method is good I have no idea on how to loop the faces in a cube and track what texture this face has.

Thanks for any suggestions

   

John Brookes, Moderator
Posted: 09 April 2013 01:31 PM   Total Posts: 732   [ # 1 ]

Did this a while ago..may be better ways, just match the texture.
http://shrewballooba.co.uk/dicetest/
doubleclick to throw

private function checkDie(rb:AWPRigidBody):int
{
 
var topFace:int
 
if (Math.abs(rb.up.y) > 0.5)
 
{
  
if (rb.up.0)
   
topFace 3
  
else
   
topFace 4
 }
 
 
if (Math.abs(rb.front.y) > 0.5)
 
{
  
if (rb.front.0)
   
topFace 2
  
else
   
topFace 5
 }
 
if (Math.abs(rb.right.y) > 0.5)
 
{
  
if (rb.right.0)
   
topFace 6
  
else
   
topFace 1
 }
 
 
//trace("You threw a " +topFace)
 
return topFace;
   

sk, Newbie
Posted: 09 April 2013 01:37 PM   Total Posts: 8   [ # 2 ]

Hey! Thanks a lot! Will try it out asap

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X