How to move rigid body with mouse?

Software: Away3D 4.x

dannycloud, Newbie
Posted: 27 June 2014 05:05 PM   Total Posts: 1

I’m trying to simulate the rolling of a die. The die is a rigid body (cube),  with mass of 0 and gravity set to 0, 0, 0 so it doesn’t fall immediately, and height of 250. The screen is surrounded by walls so the die don’t fall over.

Now I want the user to be able to drag the die around the view before rolling it. I first tried to move setting the position of the die to the cursor position. This worked but the die will not collide with the walls because I was simply teleporting the die to a new position, instead of moving it with forces. 

I tried using forces to move the die, here is my code:

if (mainView.mouseX previousMouseX){
     previousMouseX 
mainView.mouseX;
     
dice1RigidBody.applyCentralForce(new Vector3D(-500));
    
}
   
else if (mainView.mouseX previousMouseX){
     previousMouseX 
mainView.mouseX;
     
dice1RigidBody.applyCentralForce(new Vector3D(500));
   
}
    
   
if (mainView.mouseY previousMouseY){
     previousMouseY 
mainView.mouseY;
     
dice1RigidBody.applyCentralForce(new Vector3D(00, -5));
   
}
    
   
else if (mainView.mouseY previousMouseY){
     previousMouseY 
mainView.mouseY;
     
dice1RigidBody.applyCentralForce(new Vector3D(005));
   

The movement is really sloppy and not realistic. How can I better simulate the movement of a die with the mouse cursor?

thank you

   

John Brookes, Moderator
Posted: 28 June 2014 10:41 AM   Total Posts: 732   [ # 1 ]

You can either add a constraint between the mouse and your rb
eg
http://away3d.com/forum/viewthread/4396/

or do something like the character demo. Using collision flags to swap between character and standard rigidbody.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X