Godot Version
godot 4.6
Question
Hi ive started working in godot and ive added a crouch mechanic that works fine, but for some reason whenever i launch it, the character is always crouched other than that works fine, anyone know how to fix this?
extends CharacterBody3D
@export_range(5, 10, 0.1) var CROUCH_SPEED : float =7.0
@export var ANIMATIONPLAYER : AnimationPlayer
const SPEED = 6
var _is_Crouching : bool = true
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity += get_gravity() * delta
if Input.is_action_just_pressed ("CROUCH"):
toggle_crouch()
gameplay actions.
var input_dir := Input.get_vector("Left", "Right", "Forward", "Backwards")
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
if Input.is_action_pressed("Sprint"):
velocity.z *= 2
velocity.x *= 2
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
func toggle_crouch():
if _is_Crouching == true:
ANIMATIONPLAYER.play("Crouch", -1, -CROUCH_SPEED, true)
elif _is_Crouching == false:
ANIMATIONPLAYER.play("Crouch", -1, CROUCH_SPEED)
_is_Crouching = !_is_Crouching