Godot Version
Godot 4.7.2 stable.steam
Question
I’m very new to coding and this is my first ever project (barebones 3D platformer). I’m having an issue while setting up controller inputs for looking around in 3rd person.
I’ve followed this video https://www.youtube.com/watch?v=D_Cz6I83TUY on setting up the 3rd person camera with a controller and ran into an error that no one else seems to have run into and I have no clue what its asking me to do. Here’s a pic with all the errors that pop up:
I didn’t have an issue with this before, but once I started adding in the extra code it’s started to break and I have no idea why. I’ve tried moving code around/fixing small mistakes but it still persists. Here’s the script to look at:
extends CharacterBody3D
@onready var camera_pivot: Node3D = %"Camera Pivot"
@onready var camera_controller: Node3D = %"Camera Controller"
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
func \_physics_process(delta: float) -> void:
var axis_vector = Input.get_vector("camera_left", "camera_right", "camera_up", "camera_down")
if axis_vector.length() >= 0.2:
camera_pivot.rotate_y(deg_to_rad(-axis_vector.x \* 1.5))
camera_controller.rotate_x(deg_to_rad(-axis_vector.y \* 1.5))
camera_controller.rotation.x = clamp(camera_controller.rotation.x, deg_to_rad(-80.0, deg_to_rad(30.0))
\# Add the gravity.
if not is_on_floor():
velocity += get_gravity() \* delta
\# Handle jump.
if Input.is_action_just_pressed("x_button") and is_on_floor():
velocity.y = JUMP_VELOCITY
\# Get the input direction and handle the movement/deceleration.
\# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
\# New vector3 direction taking into account the user input and camera location
var direction := (camera_pivot.transform.basis \* Vector3(input_dir.x, 0, input_dir.y)).normalized()
\# Rotate character mesh to face direction of movement
if input_dir != Vector2(0,0):
body_mesh.rotation_degrees.y = camera_pivot.rotation_degrees.y - rad_to_deg(indput_dir.angle()) - 90
if is_on_floor():
align_with_floor(ray_cast_3d.get_collision_normal())
global_transform = global_transform.interpolate_with(xform, 0.3)
elif not is_on_floor():
align_with_floor(Vector3.UP)
global_transforrm = global_transform.interpolate_with(xform, 0.3)
if direction:
velocity.x = direction.x \* SPEED
velocity.z = direction.z \* SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
\# Make camera controller match the position of myself
camera_pivot.position = lerp(camera_pivot.position, Vector3(position.x, position.y + 2.0, position.z), 0.15)
Any help would be appreciated! I’m worried if I keep messing with it I’ll break it even more


