Using motors

hi to all!

I'd like my object to rotate around its center but staying at the same position
since I haven't found an obvious solution, I created a second body (circle with radius=1, density=0) at the same position and created a revolute joint between them

my problem is that I need the body rotating at constant speed. but if the body density is low, any other body colliding with it will slow down of fasten up the body. if it has high density, I can use stronger torque, but it will accelerate very slowly

the other problem is that I want to change direction of its rotation
I tried to use SetMotorSpeed or SetMotorTorque, but none of them works 🙁
Are you using pixel units? With pixel units torques need to be very large numbers. Try using a higher density for your rotating shape than your other moving shapes. Set the max torque on the motor very high.
Erin Catto wrote:
Are you using pixel units? With pixel units torques need to be very large numbers. Try using a higher density for your rotating shape than your other moving shapes. Set the max torque on the motor very high.

tanks for the answer!

yes, I use pixel units
if i use higher density, other object won't influence the rotation of the body, but it accelerates very slowly
and if i use high torque, it will become very fast, can i set a maximum angular speed for the body?

so, you say that by using setspeed and settorque functions I should reverse the rotation?
is there any way to do that instantly?
so, for example I want my object to rotate a constant speed, and when I click on it, it should rotate the same speed but in the opposite direction
You should set the RevoluteJointDef motor parameters: speed and motorTorque. Or are you applying a torque directly to the body?

The motor tries to achieve the specified speed, up to the maximum torque. See the MotorsAndLimits test.

If you need the body to stop rotating instantly, you'll have to do something special. I would just set the angular velocity directly in this case. Also, you should change the motor settings to keep it at the right speed. There's a proper interface for this in 2.0.

Original thread: https://box2d.org/forum/viewtopic.php?t=232