How to get angle of rotation of physics body?

There’s a command for the velocity.
x,y=object:getLinearVelocity()
I can’t find anything for the angle though, just these:

object:applyTorque()object:applyAngularImpulse()
object.angularVelocity --overrides other rotational forces
object.angularDamping=0; object.isFixedRotation=true

ex: Say on keypress ‘a’ I apply object:applyTorque(5) to a body, and when the angle gets to 45 degrees I want a switch to activate to make a door appear. What variable do I check for?
This can be done with manually via angle=0; if key.a… angle+=1… obj=r*cos(angle)+originX…etc. But if I’m using the physics engine I would need to replicate the torque calculation to keep track of the angle or mbe I can create some secondary physics object that is at the circumferene that will move according to the torque of the first and I can determine the current angle maybe…that seems convoluted but maybe that will work, guessing that requires a multi-chained body (unfamiliar still will look into).

  1. You can make a simple comparison
    if object.rotation >= 45 then
    -- do something
    end
  1. To create a second physical body that moves based on the torque of the first body, you can try using a physics joint (If this is a continuous behavior, such as a rotating wheel to move vehicle).
1 Like