HingeJoint
This component creates a hinge joint.
Two objects, node0 and node1, will lose all but a single degree of freedom: they can now only rotate around the X-axis of the node that contains this component. The rotation can also be constrained by the angle parameter around the Y-axis. For example, angle = 15. would allow the bodies to rotate between -15 and +15 degrees, where the Y-axis of the joint represents 0.
This joint can be used to make doors, fans, and even simulate a 2D ball-and-swing joint.
The joint can be added as a component to either one of the two bodies, or to a new entity with a single joint component — the behavior of the joint is the same either way.
Only one joint can be added to a single node.
This component is provided by the engine.physics_core module, which is included in the engine.core module.
Example:
require engine.core
// Create first body
let nodeA = create_node(NodeData(position = float3(0, 10, 10), scale = float3(1, 1, 10)))
add_component(nodeA, new RigidBody())
add_component(nodeA, new BoxCollider())
// Create second body
let nodeB = create_node(NodeData(position = float3(0, 10, -10), scale = float3(1, 1, 10)))
add_component(nodeB, new RigidBody())
add_component(nodeB, new BoxCollider())
// Create joint that keeps two bodies at the distance they were created at - 20
add_component(create_node(NodeData(position = float3(0, 10, 0))), new HingeJoint(
node0 = nodeA,
node1 = nodeB,
angle = 45.
))
Classes
- HingeJoint : NativeComponent
A simple hinge joint. Rotate second body around first (or vise versa).
- Properties:
- HingeJoint.node0: NodeId
- HingeJoint.node0 =(value: NodeId)
A first body of the joint. It should have an active RigidBody component.
- Arguments:
value : NodeId
- HingeJoint.node1: NodeId
- HingeJoint.node1 =(value: NodeId)
A second body of the joint. It should have an active RigidBody component.
- Arguments:
value : NodeId
- HingeJoint.allowCollision: bool
- HingeJoint.allowCollision =(value: bool)
Used for disabling collision between the joined bodies. Default is false, disables collision.
- Arguments:
value : bool
- HingeJoint.angle: float
- HingeJoint.angle =(value: float)
Allowed rotation around local Y axis of the node
- Arguments:
value : float
- HingeJoint.frictionTorque: float
- HingeJoint.frictionTorque =(value: float)
Maximum amount of torque to apply as friction
- Arguments:
value : float
- HingeJoint.softLimit: float2
- HingeJoint.softLimit =(value: float2)
Soft limit. When the angle goes out of bounds, the soft limits can pull it back with a spring force.
The spring settings are packed to float2 where x is a spring frequency in Hz, and y is a spring damping (0 = no damping, 1 = critical damping, >1 = overdamp).
If frequency = 0, the soft limit is disabled and the constraint will have hard limits.
- Arguments:
value : float2