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 either set_third_person_rotation() (radians) or 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.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
Setter
void
set_follow_target_node(Node3D
target_node)
Example
pcam.set_follow_target_node(player_node)
Follow Target Offset
Type: Vector3
Default: Vector3(0,0,0)
Offsets the follow target's position.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
Setter
void
set_follow_target_offset(Vector3
offset)
Example
pcam.set_follow_target_offset(Vector3(1, 1, 1))
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.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
Damping Value
Type: float
Default: 10
Defines the damping amount.
Lower value = slower / heavier camera movement.
Higher value = faster / sharper camera movement.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
Setter
void
set_follow_damping_value(float
damping_value)
Example
pcam.set_follow_damping_value(5)
Spring Length
Type: float
Default: 1.0
Defines the SpringArm3D
node's spring length.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
Setter
void
set_spring_arm_spring_length(float
length)
Example
pcam.set_spring_arm_spring_length(4.2)
Collision Mask
Type: int
Default: 1
Defines the SpringArm3D
node's Collision Mask
.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
Setter
void
set_spring_arm_collision_mask(int
mask_int)
Example
pcam.set_spring_arm_collision_mask(4)
Shape
Type: Shape3D
Default: null
Defines the SpringArm3D
node's Shape3D
.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
Margin
Type: float
Default: 0.01
Defines the SpringArm3D
node's Margin
.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
Methods
Third Person Rotation
Type: Vector3
Default: Vector3(0,0,0)
Defines the rotation (in radians) value of the Third Person SpringArm3D
node.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
Setter
void
set_third_person_rotation(Vector3
spring_arm_rotation)
Example
pcam.set_third_person_rotation(Vector3(-30, 0, 0))
Third Person Rotation Degrees
Type: Vector3
Default: Vector3(0,0,0)
Defines the rotation (in degrees) value of the Third Person SpringArm3D
node.
Note: During runtime, properties should be modified and read via their setters & getters respectively.
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)