R3d.World:createHingeJoint
Available since: Gideros 2019.10
Class: R3d.World
Description
Creates a hinge joint.
r3d.World:createHingeJoint(bodyA,bodyB,anchorX,anchorY,anchorZ,axisX,axisY,axisZ[,params])
The HingeJoint class describes a hinge joint (or revolute joint) between two rigid bodies.
The hinge joint only allows rotation around an anchor point and around a single axis (the hinge axis). This joint can be used to simulate doors or pendulums for instance.
You need to provide the pointers to the two rigid bodies, the coordinates of the anchor point (in world-space) and also the hinge rotation axis (in world-space). The two bodies need to be in a correct position when the joint is created.
Note this method will also return a pointer to the HingeJoint object that has been created internally. You will then be able to use that pointer to change properties of the joint and also to destroy it at the end
Parameters
bodyA: (r3d body) body A
bodyB: (r3d body) body B
anchorX: (number) x anchor
anchorY: (number) y anchor
anchorZ: (number) z anchor
axisX: (number) x axis rotation
axisY: (number) y axis rotation
axisZ: (number) z axis rotation
params: (table) optional any of the followings:
- isCollisionEnabled (bool)
- isLimitEnabled (bool)
- minAngleLimit (number)
- maxAngleLimit (number)
- isMotorEnabled (bool)
- motorSpeed (number)
- maxMotorTorque (number)
Limits
With the hinge joint, you can constrain the motion range using limits. The limits of the hinge joint are the minimum and maximum angle of rotation allowed with respect to the initial angle between the bodies when the joint is created.
The limits are disabled by default. If you want to use the limits, you first need to enable them by setting the isLimitEnabled variable of the HingeJointInfo object to true before you create the joint. You also have to specify the minimum and maximum limit angles (in radians) using the minAngleLimit and maxAngleLimit variables of the joint info object.
Note the minimum limit angle must be in the range [−2π;0] and the maximum limit angle must be in the range [0;2π]
Motor
A motor is also available for the hinge joint. It can be used to rotate the bodies around the hinge axis at a given angular speed and such that the torque applied to rotate the bodies does not exceed a maximum allowed torque.
The motor is disabled by default. If you want to use it, you first have to activate it using the isMotorEnabled boolean variable of the HingeJointInfo object before you create the joint. Then, you need to specify the angular motor speed (in radians/seconds) using the motorSpeed variable and also the maximum allowed torque (in Newton · meters) with the maxMotorTorque variable.
Example
require "reactphysics3d"
local world = r3d.World.new(0, -9.8, 0)
local hj = world:createHingeJoint(player1.body, obj01.body, 2, 4, 0, 0, 1, 0, {
isCollisionEnabled=true,
isMotorEnabled=true, motorSpeed=-2*8, maxMotorTorque=2*8,
})
- R3d.World
- R3d.World.new
- R3d.World:createBallAndSocketJoint
- R3d.World:createBody
- R3d.World:createFixedJoint
- R3d.World:createHingeJoint
- R3d.World:createSliderJoint
- R3d.World:destroyBody
- R3d.World:destroyJoint
- R3d.World:getGravity
- R3d.World:raycast
- R3d.World:setEventListener
- R3d.World:setGravity
- R3d.World:step
- R3d.World:testCollision
- R3d.World:testOverlap