Skip to main content
Version: latest - a1.172.0 ⚖️

⛓️ Cable

A Cable represents a Physics Constraint which joins two Actors with a rope-like visual representation between them

Server Only🔁Not Distributable🧑‍💻API Source
👪Inheritance
This class shares methods and events from Base Entity, Base Actor, Base Paintable.

nanos world Cables are composed primarily of two Unreal Engine components: a Cable and a PhysicsConstraint. The first is used for visual purposes only and the second one gives the effective physical effects that are applied to each end of the Cable.

info

Cable visuals can be tweaked with :SetForces(), :SetCableSettings() and :SetRenderingSettings() methods. Those methods don’t have effect on the physics being applied and only have effects on the visual representation.

Cable physics can be tweaked with :SetAngularLimits() and :SetLinearLimits().

After attaching the two sides of your cable, the physics can be tweaked to affect how the constraint will affect the objects.

tip

Cables are automatically destroyed when one of the sides are detached

🎒 Examples​

Server/Index.lua
local my_cable = Cable(Vector())
local cube_01 = Prop(Vector(100, 100, 100), Rotator(), "nanos-world::SM_Cube")
local cube_02 = Prop(Vector(200, 0, 100), Rotator(), "nanos-world::SM_Cube")

my_cable:AttachStartTo(cube_01)
my_cable:AttachEndTo(cube_02)

🛠 Constructors​

Default Constructor​

No description provided

local my_cable = Cable(location, enable_visuals?, spawn_mode?)
Parameters
NameTypeDescription
locationVectorWorld location to spawn at
enable_visuals?booleanToggles the cable visuals Default true
spawn_mode?SpawnModePass SpawnMode.AfterConstructor or SpawnMode.Manual to avoid immediately sending the entity to clients and improve performance when you want to configure it by setting several configs. Must call FinishSpawn() after all Default SpawnMode.Immediate

🗿 Static Functions​

This class doesn't have own static functions.

Inherited static functions

🦠 Functions​

Appearance
IsVisible: booleanReturns true if this cable is visible
SetCableSettingsSet the overall settings for this cable (visuals only)
SetRenderingSettingsSet the rendering settings of this cable (visuals only)
SetVisibilitySets whether the cable is visible or not (visuals only, the constraint keeps working)
Attachments
AttachEndTo: booleanAttaches the end of this cable to another Actor at a specific bone or relative location
AttachStartTo: booleanAttaches the beginning of this cable to another Actor at a specific bone or relative location
DetachEndDetaches the End of this Cable
DetachStartDetaches the Start of this Cable
GetAttachedEndTo: Base Actor or nilGets the Actor attached to End
GetAttachedStartTo: Base Actor or nilGets the Actor attached to Start
Motors
SetAngularMotorSLERPOrientationSettingsSets whether the SLERP angular orientation drive is enabled and the target orientation
SetAngularMotorSLERPVelocitySettingsSets whether the SLERP angular velocity drive is enabled and the target angular velocity
SetAngularMotorTwistAndSwingOrientationSettingsSets which twist and swing angular orientation drives are enabled and the target orientation
SetAngularMotorTwistAndSwingVelocitySettingsSets which twist and swing angular velocity drives are enabled and the target angular velocity
SetLinearMotorPositionSettingsSets which linear position drives are enabled and the target position
SetLinearMotorVelocitySettingsSets which linear velocity drives are enabled and the target velocity
Physics
SetAngularLimitsSets the Physics Angular Limits of this cable
SetForcesSet the forces the cable has applied (visuals only)
SetLinearLimitsSets the Physics Linear Limits of this cable
SetPhysicsConstraintSettingsSet the Physics Constraint related settings for this cable

Inherited functions

Appearancefunctions​

IsVisibleOptimal​

Returns true if this cable is visible

local is_visible = my_cable:IsVisible()
Returns
TypeDescription
booleanWhether this cable is visible

SetCableSettingsOptimal​

Set the overall settings for this cable (visuals only)

my_cable:SetCableSettings(length, num_segments?, solver_iterations?, enable_stiffness?)
Parameters
NameTypeDescription
lengthfloatRest length of the cable. Default is 100. Min is 0
num_segments?integerHow many segments the cable has. Default is 10. Min is 1 Default 10
solver_iterations?integerThe number of solver iterations controls how 'stiff' the cable is. Default is 1. Max is 16 Default 1
enable_stiffness?booleanAdd stiffness constraints to cable. Default is true Default true

SetRenderingSettingsOptimal​

Set the rendering settings of this cable (visuals only)

my_cable:SetRenderingSettings(width, num_sides, tile_material)
Parameters
NameTypeDescription
widthfloatHow wide the cable geometry is. Default is 6
num_sidesintegerNumber of sides of the cable geometry. Default is 4
tile_materialintegerHow many times to repeat the material along the length of the cable. Default is 1

SetVisibilityOptimal​

Sets whether the cable is visible or not (visuals only, the constraint keeps working)

my_cable:SetVisibility(is_visible)
Parameters
NameTypeDescription
is_visiblebooleanWhether the cable is visible or not

Attachmentsfunctions​

AttachEndToSlow​

Attaches the end of this cable to another Actor at a specific bone or relative location

For optimization, it is recommended to be the last method to call when setting up the cable.

Note¹: You can attach the end only, and the start will fixed at the Cable's location.

Note²: If no linear limit is set, the entity will be snapped to the other actor. Alternatively you can keep a physics constraint offset by passing it as parameter

local attached_successfully = my_cable:AttachEndTo(other, relative_location?, bone_name?, constraint_offset?)
Parameters
NameTypeDescription
otherBase ActorThe Actor to attach to
relative_location?VectorOffset relative to the Actor or bone Default Vector(0, 0, 0)
bone_name?stringWhich bone to attach to. If empty it will be attached to the Actor, otherwise to the Mesh at the bone/socket Default
constraint_offset?VectorThe physics constraint offset applied to the attached end, in the local space of the other Actor Default Vector(0, 0, 0)
Returns
TypeDescription
booleanif it was attached successfully

AttachStartToModerate​

Attaches the beginning of this cable to another Actor at a specific bone or relative location

For optimization, it is recommended attaching start first if you wish to attach both start and end, to avoid double calculations

local attached_successfully = my_cable:AttachStartTo(other, relative_location?, bone_name?)
Parameters
NameTypeDescription
otherBase ActorThe Actor to attach to
relative_location?VectorOffset relative to the Actor or bone Default Vector(0, 0, 0)
bone_name?stringWhich bone to attach to. If empty it will be attached to the Actor, otherwise to the Mesh at the bone/socket Default
Returns
TypeDescription
booleanif it was attached successfully

DetachEndOptimal​

Detaches the End of this Cable

my_cable:DetachEnd()

DetachStartOptimal​

Detaches the Start of this Cable

my_cable:DetachStart()

GetAttachedEndToOptimal​

Gets the Actor attached to End

local attached_actor = my_cable:GetAttachedEndTo()
Returns
TypeDescription
Base Actor or nilActor attached to End

GetAttachedStartToOptimal​

Gets the Actor attached to Start

local attached_actor = my_cable:GetAttachedStartTo()
Returns
TypeDescription
Base Actor or nilActor attached to Start

Motorsfunctions​

SetAngularMotorSLERPOrientationSettingsOptimal​

Sets whether the SLERP angular orientation drive is enabled and the target orientation

my_cable:SetAngularMotorSLERPOrientationSettings(enable_drive_slerp?, strength?, target?)
Parameters
NameTypeDescription
enable_drive_slerp?booleanEnable the SLERP angular orientation drive Default false
strength?floatPositional strength for the drive (stiffness) Default 0
target?RotatorAngular drive orientation target Default Rotator(0, 0, 0)

SetAngularMotorSLERPVelocitySettingsOptimal​

Sets whether the SLERP angular velocity drive is enabled and the target angular velocity

my_cable:SetAngularMotorSLERPVelocitySettings(enable_drive_slerp?, strength?, target?)
Parameters
NameTypeDescription
enable_drive_slerp?booleanEnable the SLERP angular velocity drive Default false
strength?floatVelocity strength of the drive (damping) Default 0
target?VectorTarget angular velocity Default Vector(0, 0, 0)

SetAngularMotorTwistAndSwingOrientationSettingsOptimal​

Sets which twist and swing angular orientation drives are enabled and the target orientation

my_cable:SetAngularMotorTwistAndSwingOrientationSettings(enable_drive_twist?, enable_drive_swing?, strength?, target?)
Parameters
NameTypeDescription
enable_drive_twist?booleanEnable the twist angular orientation drive Default false
enable_drive_swing?booleanEnable the swing angular orientation drive Default false
strength?floatPositional strength for the drive (stiffness) Default 0
target?RotatorAngular drive orientation target Default Rotator(0, 0, 0)

SetAngularMotorTwistAndSwingVelocitySettingsOptimal​

Sets which twist and swing angular velocity drives are enabled and the target angular velocity

my_cable:SetAngularMotorTwistAndSwingVelocitySettings(enable_drive_twist?, enable_drive_swing?, strength?, target?)
Parameters
NameTypeDescription
enable_drive_twist?booleanEnable the twist angular velocity drive Default false
enable_drive_swing?booleanEnable the swing angular velocity drive Default false
strength?floatVelocity strength of the drive (damping) Default 0
target?VectorTarget angular velocity Default Vector(0, 0, 0)

SetLinearMotorPositionSettingsOptimal​

Sets which linear position drives are enabled and the target position

my_cable:SetLinearMotorPositionSettings(enable_drive_x?, enable_drive_y?, enable_drive_z?, strength?, target?)
Parameters
NameTypeDescription
enable_drive_x?booleanEnable the linear position drive on X Default false
enable_drive_y?booleanEnable the linear position drive on Y Default false
enable_drive_z?booleanEnable the linear position drive on Z Default false
strength?floatPositional strength for the drive (stiffness) Default 0
target?VectorTarget position Default Vector(0, 0, 0)

SetLinearMotorVelocitySettingsOptimal​

Sets which linear velocity drives are enabled and the target velocity

my_cable:SetLinearMotorVelocitySettings(enable_drive_x?, enable_drive_y?, enable_drive_z?, strength?, target?)
Parameters
NameTypeDescription
enable_drive_x?booleanEnable the linear velocity drive on X Default false
enable_drive_y?booleanEnable the linear velocity drive on Y Default false
enable_drive_z?booleanEnable the linear velocity drive on Z Default false
strength?floatVelocity strength of the drive (damping) Default 0
target?VectorTarget velocity Default Vector(0, 0, 0)

Physicsfunctions​

SetAngularLimitsOptimal​

Sets the Physics Angular Limits of this cable

my_cable:SetAngularLimits(swing_1_motion, swing_2_motion, twist_motion, swing_1_limit?, swing_2_limit?, twist_limit?)
Parameters
NameTypeDescription
swing_1_motionConstraintMotionIndicates whether the Swing1 limit is used
swing_2_motionConstraintMotionIndicates whether the Swing2 limit is used
twist_motionConstraintMotionIndicates whether the Twist limit is used
swing_1_limit?floatAngle of movement along the XY plane. This defines the first symmetric angle of the cone Default 0
swing_2_limit?floatAngle of movement along the XZ plane. This defines the second symmetric angle of the cone Default 0
twist_limit?floatSymmetric angle of roll along the X-axis Default 0

SetForcesModerate​

Set the forces the cable has applied (visuals only)

my_cable:SetForces(force, gravity_scale?)
Parameters
NameTypeDescription
forceVectorForce vector (world space) applied to all particles in cable. Default is Vector(0, 0, 0)
gravity_scale?floatScaling applied to world gravity affecting this cable. Default is 1 Default 1

SetLinearLimitsOptimal​

Sets the Physics Linear Limits of this cable

If use_soft_constraint is enabled, then stiffness and damping will be used, otherwise restitution will be used.

Note: this method must be called before attaching any cable end

my_cable:SetLinearLimits(x_motion, y_motion, z_motion, limit?, restitution?, use_soft_constraint?, stiffness?, damping?)
Parameters
NameTypeDescription
x_motionConstraintMotionIndicates the linear constraint applied along the X-axis. Free implies no constraint at all. Locked implies no movement along X is allowed. Limited implies the distance in the joint along all active axes must be less than the Distance provided
y_motionConstraintMotionIndicates the linear constraint applied along the Y-axis. Free implies no constraint at all. Locked implies no movement along Y is allowed. Limited implies the distance in the joint along all active axes must be less than the Distance provided
z_motionConstraintMotionIndicates the linear constraint applied along theZX-axis. Free implies no constraint at all. Locked implies no movement along Z is allowed. Limited implies the distance in the joint along all active axes must be less than the Distance provided
limit?floatThe distance allowed between the two joint reference frames. Distance applies on all axes enabled (one axis means line, two axes implies circle, three axes implies sphere) Default 0
restitution?floatControls the amount of bounce when the constraint is violated. A restitution value of 1 will bounce back with the same velocity the limit was hit. A value of 0 will stop dead Default 0
use_soft_constraint?booleanWhether we want to use a soft constraint (spring) Default false
stiffness?floatStiffness of the soft constraint. Only used when Soft Constraint is on Default 0
damping?floatDamping of the soft constraint. Only used when Soft Constraint is on Default 0

SetPhysicsConstraintSettingsOptimal​

Set the Physics Constraint related settings for this cable

my_cable:SetPhysicsConstraintSettings(disable_collision)
Parameters
NameTypeDescription
disable_collisionbooleanIf true, the collision between the two rigid bodies of the constraint will be disabled

🚀 Events​

This class doesn't have own events.