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(-5, 0, 0));
}
else if (mainView.mouseX > previousMouseX){
previousMouseX = mainView.mouseX;
dice1RigidBody.applyCentralForce(new Vector3D(5, 0, 0));
}
if (mainView.mouseY > previousMouseY){
previousMouseY = mainView.mouseY;
dice1RigidBody.applyCentralForce(new Vector3D(0, 0, -5));
}
else if (mainView.mouseY < previousMouseY){
previousMouseY = mainView.mouseY;
dice1RigidBody.applyCentralForce(new Vector3D(0, 0, 5));
}
The movement is really sloppy and not realistic. How can I better simulate the movement of a die with the mouse cursor?
thank you