Godot Version
version 4.3
Question
I’ve been following the StayAtHomeDev’s tutorial how to make a basic movement and camera rotation and at the camera rotation, when i try to start the game, it shows me a blank screen and shows me this warning
does anybody know how to fix it?
this is my code
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
@export var TILT_LOWER_LIMIT := deg_to_rad(-90.0)
@export var TILT_UPPER_LIMIT := deg_to_rad(90.0)
@export var CAMERA_CONTROLLER : Camera3D
var _mouse_input : bool = false
var _rotation_input : float
var _tilt_input : float
var _mouse_rotation : Vector3
var _player_rotation : Vector3
var _camera_rotation : Vector3
func _unhandled_input(event):
_mouse_input = event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED
if _mouse_input:
_rotation_input = -event.relative.x
_tilt_input = -event.relative.y
print(Vector2(_rotation_input,_tilt_input))
func _update_camera(delta):
#Rotate camera using euler rotation
_mouse_rotation.x += _tilt_input * delta
_mouse_rotation.x = clamp(_mouse_rotation.x, TILT_LOWER_LIMIT, TILT_UPPER_LIMIT)
_mouse_rotation.y += _rotation_input * delta
CAMERA_CONTROLLER.transform.basis = Basis.from_euler(_mouse_rotation)
CAMERA_CONTROLLER.rotation.z = 0.0
_rotation_input = 0.0
_tilt_input = 0.0
func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _input(event):
if event.is_action_pressed("exit"):
get_tree().quit()
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
_update_camera(delta)
# Handle jump.
if Input.is_action_just_pressed("jump") 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_forward", "move_backward")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
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()