How to use joints
Learn how to create, update, and remove joints between two ships.
Introduction
Joints can be used to connect two ships (or a ship and the world) with a variety of connection types including fixed rotation, position, specific locked axis, or other setups.
If you want to create something like a rope or a bearing, then you're in the right place.
Steps
Creating a joint
To create a joint, you will need:
Two body ids (which are usually obtained from a ship)
An instance of a subclass of VSJoint
Two VSJointPose's to use in constructing the VSJoint
- Available VSJoint subclasses
VSFixedJoint,VSDistanceJoint,VSPrismaticJoint,VSSphericalJoint,VSRevoluteJoint,VSGearJoint,VSRackAndPinionJoint,VSD6JointDifferent joint subclasses require different amounts of parameters to be specified.
For simplicity, this page will demonstrate using the
VSFixedJoint, which requires the least parameters to set up.
Joints need to be created on the physics tick, however the GTPA has methods to allow creation of joints on the game tick.
Here is an example function (using the GTPA) which adds a fixed joint between two ships (at their center of mass, with their current rotation):
If you are looking to add a joint on the physics tick, look at how the GameToPhysicsAdapter does it.
Storing the joint id
If you are keen-eyed, you will have noticed the empty lambda we passed into the addJoint method in the previous code example.
This lambda (which is a VSJointId consumer) will be run on the physics tick once the joint has been added. The VSJointId the lambda provides you is the (integer) id which has been allocated to your joint.
Addons will often use this to store the id into a variable in a block entity for updating/removing the joint.
Updating the joint
To update an existing joint you can get the current joint, copy its properties to a new VSJoint instance and change as needed. Then construct an instance of VSJointAndId to give to the GTPA to update.
Removing the joint
To remove a joint, you simply give the GTPA a VSJointId.