This project has moved and is read-only. For the latest updates, please go here.

Help with making top-wiew door

Topics: User Forum
Jan 28, 2013 at 5:31 PM


I'm trying to make a top-view shooter. I use FixedRevoluteJoint for doors.
The concept is this:
Door is composed of a rectangle positioned (0, (-rectangle height / 2) - 10)
Doors can open in both direction.
Doors opened by the player colliding with them.
Doors are closed by pressing specific button.
Doors need to return to initial position when closed.

Rectangle position made this way because the rectangle is made by FixtureFactory which centering the rectangle.
This way i got a rectangle 10pixels over the LocalCenter.

So far I've got partial success.

What i do on initialization:
Save the body.Rotation.
Save the JointAnlge.

What i do when the close door button is pressed:
Set MotorEnabled to true.
Set a needToClose flag to true. 
Apply a motor speed in the right direction (based on the saved and the current body.Rotation).

What i do when the body.Rotation reaches or went beyond the initial body.Rotation:
Set the MotorEnabled to false.
Set MotorTorque and MotorSpeed to 0. (I don't know which one should i do, so i do both.)
Set UpperLimit and LowerLimit of the joint to the initial JointAnlge.
In the next update call i set the joint limits back to initial values.

What it produces:
When no rotation is set for the body before creating the joint it works fine.
When i apply a rotation before making the joint the door is not returning to the initial position, but to approximately 1/8 rotation backward in ccw direction.

Basicly any sollution for my problem is appreciated, but a basic explanation of the Joint's ReferenceAngle and JointAngle properties would be great too. I think the issue is laying in the lack of my understanding of these areas.

I hope you will understand what i'm trying to explain :)
If not i'll provide some code, but these parts are pretty fragmented in my code, so i decided to write it down in words.