SpringJoint
This component creates a spring joint, also known as a distance joint.
The joint will try to keep a fixed distance between two objects, node0 and node1, as defined by their positions at the moment the joint is created. The objects can rotate freely at the ends of the joint.
Each of the two bodies will try to maintain the same position between its body and the position of the joint. This allows free rotation of the bodies.
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(10, 10, 0)))
add_component(nodeA, new RigidBody())
add_component(nodeA, new SphereCollider())
// Create second body
let nodeB = create_node(NodeData(position=float3(-10, 10, 0)))
add_component(nodeB, new RigidBody())
add_component(nodeB, new SphereCollider())
// Create a joint that keeps two bodies at the distance they were created at — 20
add_component(create_node(NodeData()), new SpringJoint(
node0 = nodeA,
node1 = nodeB
))
Classes
- SpringJoint : NativeComponent
A spring joint. Keeps two bodies at a fixed distance, but allows rotations freely.
- Properties:
- SpringJoint.node0: NodeId
- SpringJoint.node0 =(value: NodeId)
A first body of the joint. It should have an active RigidBody component.
- Arguments:
value : NodeId
- SpringJoint.node1: NodeId
- SpringJoint.node1 =(value: NodeId)
A second body of the joint. It should have an active RigidBody component.
- Arguments:
value : NodeId
- SpringJoint.allowCollision: bool
- SpringJoint.allowCollision =(value: bool)
Used for disabling collision between the joined bodies. Default is false, disables collision.
- Arguments:
value : bool
- SpringJoint.spring: float2
- SpringJoint.spring =(value: float2)
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