I am trying to create something to act like a door that can open and close. I am using a hing join and everything is working that the door can open in the direction I want it to. But the problem is I don't know how to make the door stop moving. I want the door to stop at 90 degree when it is opened but the force just make the door bounce back and keep moving.
Any idea about how to make it complete stop at curtain position? How can I detect its position?
One way is to get the transform matrix from door's body and decompose to get the y-rotation degree, like
Matrix temp = body.CollisionSkin.GetPrimitiveLocal(0).Transform.Orientation * body.Orientation * Matrix.CreateTranslation(body.Position);
then use Matrix's Decompose to get the y rotation degree.
But is this a good idea? Any other way?
Here is the code, and you can just put it into the jiblibx example.
Vector3 doorSize = new Vector3(20, 5, 5);
Vector3 unmoveDoorSize = new Vector3(5, 5, 5);
door = new BoxObject(this, boxModel, doorSize, Matrix.Identity, new Vector3(0, 12.5f, 0));
Vector3 unmovePos = new Vector3(0 - unmoveDoorSize.X * 0.5f - doorSize.X * 0.5f, 12.5f, 0);
BoxObject unmoveDoor = new BoxObject(this, boxModel, unmoveDoorSize, Matrix.Identity, unmovePos);
unmoveDoor.PhysicsBody.Immovable = true;
HingeJoint join = new HingeJoint();
new Vector3(2.5f, 0f, -2.5f), //hing pos rel 0
5f, //hing half width
90, //hing forward angle
0, //hing backward angle
0f, //side way slack
if (mouseState.LeftButton == ButtonState.Pressed && leftButton == false)
Body doorBody = door.PhysicsBody;
doorBody.Velocity = new Vector3(0, 0, 50);
Any suggestion is welcome. Thank you.