Motor Joint2D Component
The MotorJoint2D
class is a component in Tsar engine used to define a joint connection between two Rigidbody2D.
The joint has to reference another Entity which has Rigidbody2D Component.
The motor joint is used to drive the relative transform between two bodies. It takes a relative position and rotation and applies the forces and torques needed to achieve that relative transform over time.
Below is animation showing the idea of MotorJoint2D with linear and angular spring.

Animation Source: https://miro.medium.com/v2/resize:fit:1400/1*hGZLebbssht62XMlmmJhZw.gif
Class Declaration
class MotorJoint2D : public Component
This class inherits from the Component
class and adds functionality related to defining a joint connection to another Rigidbody2D for simulating 2D physics.
Public Methods
Attach
bool AttachToBody(RigidBody2D& referenceBody)
Attach the joint to Entity which has the referenced Rigidbody2D. One joint component can only have one attached Rigidbody2D.
Attaching when existing joint is present will destroy the old one.
Requires valid Rigidbody2D on both entities.
- referenceBody - the Rigidbody2D component to which the joint will be attached.
Returns:
- true if joint was created successfuly.
- false if joint creation failed.
bool AttachToEntity(u64 entityID)
Attach joint directly using Entity. Requires valid Rigidbody2D on Entity.
- entityID - id of entity to which to attach joint connection.
Returns:
- true if joint was created successfuly.
- false if joint creation failed.
bool DetachFromBody()
Destroys the joint connection.
Returns:
- true if joint has been destroyed.
- false if no joint was destroyed.
Properties
The MotorJoint2D
class exposes properties (that can also be accessed via getter and setter functions). These properties allow users to manipulate the joint properties in a more intuitive manner:
bool CollideWithOther
Should the colliders attached to both bodies collide with each other?
- Get:
bool GetCollideWithOther()
- Set:
void SetCollideWithOther(bool collide)
- collide - true makes bodies collide with each other, false disables collision between them.
float CorrectionFactor
Position correction factor in the range [0; 1].
The joint tries to match position/rotation based on that factor.
- 0 has no effect.
- 1 mirrors position/rotation.
float MaxMotorForce
Specifies the maximum force the motor will apply to constrained body, in Newtons.
- Get:
float GetMaxMotorForce()
- Set:
void SetMaxMotorForce(float force)
- force - non-negative value in Newtons.
float MaxMotorTorque
Specifies the maximum torque the motor will apply to constrained body, in Newton-meters.
- Get:
float GetMaxMotorForce()
- Set:
void SetMaxMotorForce(float force)
- force - non-negative value in Newton-meters.