I’m trying to roll a dice (cube ) using gravity to lift up the dice on mouseMove and the using gravity again on mouseUp to roll the dice.
The cam is positioned looking down on the scene and dice.
It works quite well but right now the dice moves away from the mouse the more from the middle of the scene I get while holding and dragging the dice.
How do I get the dice to stick to the mouse position while carrying it?
Below is the code snippet used for attracting and carrying the cube :
private function onMouseMove(event : MouseEvent3D) : void {
if (isMouseDown) {
//currMousePos = new Vector3D(event.localPosition.x,event.localPosition.z , -600);
currMousePos = new Vector3D(event.localPosition.x, event.localPosition.z , -800);
}
}
private function handleGravity(event : Event) : void {
var gravity : Vector3D;
for each (var body:AWPRigidBody in physicsWorld.nonStaticRigidBodies) {
gravity = currMousePos.subtract(body.position);
body.position = currMousePos;
gravity.normalize();
gravity.scaleBy(100);
body.gravity = gravity;
body.rotation = new Vector3D(0, 0, 0);
}
}
thanks