Godot Version
4.3
Question
i feel like the title is pretty self explanatory, but after i restarted my computer, the character (when i start moving) slates and doesn’t turn around at all. there are no errors in the code or the debug
4.3
i feel like the title is pretty self explanatory, but after i restarted my computer, the character (when i start moving) slates and doesn’t turn around at all. there are no errors in the code or the debug
What is the code? Nice level
thanks, it’s basic code from a tut i got off youtube, i was working for weeks until now
extends CharacterBody3D # Make sure this is the first line!
@onready var camera_mount: Node3D = $camera_mount
@onready var animation_player: AnimationPlayer = $visuals/BaseMesh_Anim/AnimationPlayer
@onready var visuals: Node3D = $visuals
var walking_speed = 2.0
var running_speed = 4.0
var running = false
@export var sens_horizontal = 0.5
@export var sens_vertical = 0.5
var SPEED = 2.9
const JUMP_VELOCITY = 5
var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)
func _ready() → void:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _input(event: InputEvent) → void:
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.xsens_horizontal))
visuals.rotate_y(deg_to_rad(event.relative.xsens_horizontal))
camera_mount.rotate_x(deg_to_rad(-event.relative.y*sens_vertical))
func _physics_process(delta: float) → void:
# 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:
if running:
if animation_player.current_animation != "Root|Run":
animation_player.play("Root|Run")
else:
if animation_player.current_animation != "Root|Walk":
animation_player.play("Root|Walk")
visuals.look_at(position + direction)
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
if animation_player.current_animation != "Root|Idle":
animation_player.play("Root|Idle")
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
wait i sent the wrong code, sorry
extends CharacterBody3D # Make sure this is the first line!
@onready var camera_mount: Node3D = $camera_mount
@onready var animation_player: AnimationPlayer = $visuals/BaseMesh_Anim/AnimationPlayer
@onready var visuals: Node3D = $visuals
var walking_speed = 2.0
var running_speed = 4.0
var running = false
@export var sens_horizontal = 0.5
@export var sens_vertical = 0.5
var SPEED = 2.9
const JUMP_VELOCITY = 5
var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)
func _ready() → void:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _input(event: InputEvent) → void:
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.xsens_horizontal))
visuals.rotate_y(deg_to_rad(event.relative.xsens_horizontal))
camera_mount.rotate_x(deg_to_rad(-event.relative.y*sens_vertical))
func _physics_process(delta: float) → void:
if Input.is_action_pressed("run"):
SPEED = running_speed
running = true
else:
SPEED = walking_speed
running = false
# Add the gravity.
if not is_on_floor():
velocity += get_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:
if running:
if animation_player.current_animation != "Root|Run":
animation_player.play("Root|Run")
else:
if animation_player.current_animation != "Root|Walk":
animation_player.play("Root|Walk")
visuals.look_at(position + direction)
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
if animation_player.current_animation != "Root|Idle":
animation_player.play("Root|Idle")
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()