I have been using the code listed in the manual to orient one body around another based on the cursor position.
Where angleTarget is calculated using atan2 and the cursor position. My problem is that unless the two bodies are very close to each other the joint oscillates somewhat around the target angle instead of staying stationary. What is the best way to overcome this? I have seen a few threads related to this problem but haven't been able to find a solution that works.
Code:
... Game Loop Begin ...
float32 angleError = myJoint->GetJointAngle() - angleTarget;
float32 gain = 0.1f;
myJoint->SetMotorSpeed(-gain * angleError);
... Game Loop End ...
float32 angleError = myJoint->GetJointAngle() - angleTarget;
float32 gain = 0.1f;
myJoint->SetMotorSpeed(-gain * angleError);
... Game Loop End ...
Where angleTarget is calculated using atan2 and the cursor position. My problem is that unless the two bodies are very close to each other the joint oscillates somewhat around the target angle instead of staying stationary. What is the best way to overcome this? I have seen a few threads related to this problem but haven't been able to find a solution that works.