Hello, I have been following allong on a 3RD person godot tutorial and I have implemented “Capture the mouse” but I now cannot use my arrow keys to walk around, I have changed the input map to my own buttons but the issue was present before doing that, I had the idea of removing the mouse code to see if that was the issue and it persisted so I am a bit confused on what to do from here, I would apreciate any help on solving this issue, here is my script:
extends CharacterBody3D
@onready var camera_mount: Node3D = $Camera_Mount
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
@export var sens_horizontal = 0.5 @export var sens_vertical = 0.5
Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.xsens_horizontal ))
camera_mount.rotate_x(deg_to_rad(-event.relative.ysens_vertical))
func _phisics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
Handle jump.
if Input.is_action_just_pressed("ui_accept") 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("left", "right", "forward", "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, 5.0, SPEED)
velocity.z = move_toward(velocity.z, 5.0, SPEED)
move_and_slide()
get_vector() is already normalized, so normalizing direction is redundant. Instead of multiplying input_dir by transform basis, just call .rotated(-player_rotation.y) on the input_dir variable. Then just multiply that by speed.
extends CharacterBody3D
@onready var camera_mount: Node3D = $Camera_Mount
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
@export var sens_horizontal = 0.5
@export var sens_vertical = 0.5
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.x*sens_horizontal ))
camera_mount.rotate_x(deg_to_rad(-event.relative.y*sens_vertical))
func _phisics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") 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("left", "right", "forward", "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, 5.0, SPEED)
velocity.z = move_toward(velocity.z, 5.0, SPEED)
move_and_slide()