Vehicle Scripting: IK

From Mod Wiki

Describes IK used for vehicle positions and suspension.

Vehicle Position IK

Introduction

Inverse kinematic (IK) systems can be added to vehicles, allowing joints to be manipulated based on the player's view direction, amongst other things. For example aiming a weapon by rotating a turret and elevating a barrel, or keeping the player's hands on the steering wheel.

IK systems are added within positionDef blocks in the vehicleDef.

Properties:

  • name - the name of the IK system, to identify it in the code.
  • type - the code class to use, defines the behaviour of the IK system. Types detailed below.
  • parms - a block of key/value pairs, providing the parameters to the code class.

The IK systems can also have pitch & yaw clamps.

Types

Common

One key is common to all the IK types:

  • "weapon" - The name of the weapon associated with this IK. The player using this weapon is the player that will govern the IK. If not specified then the player in the position is the one that governs the IK. The name used here should be the value of the "weapon_name" key in the stringMap of the desired weapon.

sdVehicleIKArms

This is used for weapons that are in an arm-like configuration - for example a gun on a tripod.

Keys:

  • "jointElbow" - Joint that is yawed to aim
  • "jointWrist" - Joint that is pitched to aim - this should be down the hierarchy from "jointElbow"
  • "jointMuzzle" - Joint that needs to be pointed at the target - eg the muzzle of the weapon. This should be down the hierarchy from jointMuzzle.
  • "pitchAxis" - Selects which axis of the wrist joint is rotated to pitch towards the target.
    1 = x-axis, 2 = y-axis, 3 = z-axis. Making this value negative reverses the direction of the pitch.
    Defaults to 2.

sdVehicleSwivel

This IK type simply rotates the joint with the aim of the player associated.

Keys

  • "joint" - The joint to be rotated.

sdVehicleWeaponAimer

This IK attempts to aim the muzzle joint at the player's target. This is the form of IK integrated into the sdVehicleWeaponFixedMinigun weapon type, with differing key names.

Keys:

  • "jointShoulder" - Base joint for the aiming. If not specified, the parent joint of the elbow is used.
  • "jointElbow" - Joint that is yawed to aim
  • "jointWrist" - Joint that is pitched to aim - this should be down the hierarchy from "jointElbow"
  • "jointMuzzle" - Joint that needs to be pointed at the target - eg the muzzle of the weapon. This should be down the hierarchy from jointMuzzle.
  • "deployed_anim" - Animation that is used to gather initial calibration parameters (for models that have a differing animation at spawn)
  • "fix_barrel" - Re-orient a wayward muzzle joint
  • "invert_pitch" - Flips the pitching behaviour of the IK

sdVehicleJointAimer

This aims a single joint at the player's target.

Keys:

  • "joint" - Joint to be aimed
  • "weapon2" - Allows a second weapon to be associated with the IK, so that it also aims the joint when that weapon is in use.

sdVehicleIK_Steering

This IK is used to keep the player's hand joints attached to two joints on the vehicle - for example a steering wheel, or the handlebars of the Husky.

Keys:

  • "joint_left" - The joint the left hand should be attached to
  • "joint_right" - The joint the right hand should be attached to

Suspension IK

Introduction

Vehicle wheel & suspension parts can have a string map associated with them to give them IK. This allows joints to be specially animated, for example wishbone suspension or landing legs. They are provided with information from the vehicle part about the length of the suspension, and the suspension IK manipulate joints to make it look like the vehicle is reacting to the changing length.

Types

There are a number of different IK types that can be used, each providing a different appearance. The type is selected with the "type" key of the string map. The types of IK are listed below.

"pivot"

In this system the suspension offset is achieved by rotating a single joint.

Keys:

  • "joint" - The joint that is rotated
  • "reverse" - Reverses the response to the changing length

"double_wishbone"

This system rotates two joints, an upper joint and a lower joint.

Keys:

  • "joint_upper" - The upper joint to be rotated
  • "joint_lower" - The lower joint to be rotated
  • "lerp_scale" - How quickly the system responds to changes in suspension length. 1 means it will instantly reach the new position, 0 means it will never respond. Defaults to 0.5.

"vertical"

This type simply moves a single joint up and down as the suspension length changes.

Keys:

  • "joint" - The joint to be moved up and down.

"2jointleg"

This type rotates two joints - a "hip" joint and a "knee" joint.

Keys:

  • "joint_hip" - The hip joint.
  • "joint_knee" - The knee joint.
  • "dir_hip" - The direction (in the local space of the vehicle) the hip should rotate in. Defaults to "0 0 1"
  • "lerp_scale" - How quickly the system responds to changes in suspension length. 1 means it will instantly reach the new position, 0 means it will never respond. Defaults to 0.5.
  • "reverse" - Reverses the response to the changing length