Third Person Follow (3D)
As the name implies, this mode is meant to be used for third person camera experiences. It works by applying a SpringArm3D where the properties, such as Collison Mask, Spring Length and Margin, can be controlled from the PCam3D.
To adjust the orbit rotation around the target, use one of the following setter methods:
- set_third_person_quaternion (quaternion)
- set_third_person_rotation() (radians)
- set_third_person_rotation_degrees() (degrees).
Video Example
Properties
follow_target
Type: Node3D
Default: null
Determines which Node should be followed. The PCam3D will follow the position of the Follow Target based on the Follow Mode and its parameters.
Setter
void set_follow_target(Node3D target_node)
Example
pcam.set_follow_target(player_node)follow_offset
Type: Vector3
Default: Vector3(0,0,0)
Offsets the follow target's position.
Setter
void set_follow_offset(Vector3 offset)
Example
pcam.set_follow_offset(Vector3(1, 1, 1))follow_damping
Type: bool
Default: false
Applies a damping effect on the Camera's movement. Leading to heavier / slower camera movement as the targeted node moves around.
This is useful to avoid sharp and rapid camera movement.
damping_value
Type: Vector2
Default: Vector2(0.1, 0.1)
Defines the damping amount. The ideal range should be somewhere between 0-1, likely somewhere around 0.1-0.25.
The damping amount is specified in the individual axis. X and Y for 2D and X, Y and Z for 3D scenes. To have the damping be consistent in all directions, simply supply the same value in all slots.
Lower value = faster / sharper camera movement.
Higher value = slower / heavier camera movement.
Setter
void set_follow_damping_value(Vector2 damping_value)
Example
pcam.set_follow_damping_value(Vector2(0.2, 0.2))spring_length
Type: float
Default: 1.0
Defines the SpringArm3D node's spring length. This is the equivalent of defining the distance property in other FollowModes.
collision_mask
Type: int
Default: 1
Defines the SpringArm3D node's Collision Mask.
A simplified helper setter method can be found in the example code below.
Setter
void set_collision_mask(int mask_int)
void set_collision_mask_value(int mask_layer, bool enable)
Example
# Use this to assign a specific layer value.
# Fairly complex to use, so the function below this is recommended.
pcam.set_collision_mask(4)
# Use this helper method to enable or disable a specific layer.
pcam.set_collision_mask_value(2, true)vertical_rotation_offset
Type: float
Default: 0
Applies a rotational offset to the Third Person follow_mode in the X axis.
Setter
void set_vertical_rotation_offset(float vertical_offset)
Example
pcam.set_vertical_rotation_offset(42)horizontal_rotation_offset
Type: float
Default: 0
Applies a rotational offset to the Third Person follow_mode in the Y axis.
Setter
void set_horizontal_rotation_offset(float horizontal_offset)
Example
pcam.set_horizontal_rotation_offset(42)Methods
Rotation (Quaternion)
Type: Quaternion
Default: n/a
Defines the quaternion value of the Third Person SpringArm3D node.
Setter
void set_third_person_quaternion(Quaternion spring_arm_rotation_deg)
Example
pcam.set_third_person_quaternion(quaternion)Rotation (Radians)
Type: Vector3
Default: Vector3(0,0,0)
Defines the rotation (in radians) value of the Third Person SpringArm3D node.
Setter
void set_third_person_rotation(Vector3 spring_arm_rotation)
Example
pcam.set_third_person_rotation(Vector3(-30, 0, 0))Rotation (Degrees)
Type: Vector3
Default: Vector3(0,0,0)
Defines the rotation (in degrees) value of the Third Person SpringArm3D node.
Setter
void set_third_person_rotation_degrees(Vector3 spring_arm_rotation_deg)
Example
pcam.set_third_person_rotation_degrees(Vector3(-30, 0, 0))Getter
Vector3 get_third_person_rotation_degrees()
Example
pcam.get_third_person_rotation_degrees()Example Setup
var mouse_sensitivity: float = 0.05
var min_yaw: float = 0
var max_yaw: float = 360
var min_pitch: float = -89.9
var max_pitch: float = 50
func _unhandled_input(event) -> void:
# Trigger whenever the mouse moves.
if event is InputEventMouseMotion:
var pcam_rotation_degrees: Vector3
# Assigns the current 3D rotation of the SpringArm3D node - to start off where it is in the editor.
pcam_rotation_degrees = pcam.get_third_person_rotation_degrees()
# Change the X rotation.
pcam_rotation_degrees.x -= event.relative.y * mouse_sensitivity
# Clamp the rotation in the X axis so it can go over or under the target.
pcam_rotation_degrees.x = clampf(pcam_rotation_degrees.x, min_pitch, max_pitch)
# Change the Y rotation value.
pcam_rotation_degrees.y -= event.relative.x * mouse_sensitivity
# Sets the rotation to fully loop around its target, but without going below or exceeding 0 and 360 degrees respectively.
pcam_rotation_degrees.y = wrapf(pcam_rotation_degrees.y, min_yaw, max_yaw)
# Change the SpringArm3D node's rotation and rotate around its target.
pcam.set_third_person_rotation_degrees(pcam_rotation_degrees)