Up to date

This page is up to date for Godot 4.0. If you still find outdated information, please open an issue.

SpringArm3D

Inherits: Node3D < Node < Object

A helper node, mostly used in 3rd person cameras.

Description

The SpringArm3D node is a node that casts a ray (or collision shape) along its z axis and moves all its direct children to the collision point, minus a margin.

The most common use case for this is to make a 3rd person camera that reacts to collisions in the environment.

The SpringArm3D will either cast a ray, or if a shape is given, it will cast the shape in the direction of its z axis.

If you use the SpringArm3D as a camera controller for your player, you might need to exclude the player's collider from the SpringArm3D's collision check.

Properties

int

collision_mask

1

float

margin

0.01

Shape3D

shape

float

spring_length

1.0

Methods

void

add_excluded_object ( RID RID )

void

clear_excluded_objects ( )

float

get_hit_length ( )

bool

remove_excluded_object ( RID RID )


Property Descriptions

int collision_mask = 1

  • void set_collision_mask ( int value )

  • int get_collision_mask ( )

The layers against which the collision check shall be done. See Collision layers and masks in the documentation for more information.


float margin = 0.01

  • void set_margin ( float value )

  • float get_margin ( )

When the collision check is made, a candidate length for the SpringArm3D is given.

The margin is then subtracted to this length and the translation is applied to the child objects of the SpringArm3D.

This margin is useful for when the SpringArm3D has a Camera3D as a child node: without the margin, the Camera3D would be placed on the exact point of collision, while with the margin the Camera3D would be placed close to the point of collision.


Shape3D shape

The Shape3D to use for the SpringArm3D.

When the shape is set, the SpringArm3D will cast the Shape3D on its z axis instead of performing a ray cast.


float spring_length = 1.0

  • void set_length ( float value )

  • float get_length ( )

The maximum extent of the SpringArm3D. This is used as a length for both the ray and the shape cast used internally to calculate the desired position of the SpringArm3D's child nodes.

To know more about how to perform a shape cast or a ray cast, please consult the PhysicsDirectSpaceState3D documentation.


Method Descriptions

void add_excluded_object ( RID RID )

Adds the PhysicsBody3D object with the given RID to the list of PhysicsBody3D objects excluded from the collision check.


void clear_excluded_objects ( )

Clears the list of PhysicsBody3D objects excluded from the collision check.


float get_hit_length ( )

Returns the spring arm's current length.


bool remove_excluded_object ( RID RID )

Removes the given RID from the list of PhysicsBody3D objects excluded from the collision check.