Movement does not work

Godot Version

v4.4.1.stable.official [49a5bc7b6]

Question


I can’t move after add sword and animate it. if i press E my game process what i pressed before, jumping moving etc.My print functions are work, if i above plane it turns false or pressed space it turns true. Can someone help?

Code

extends CharacterBody3D

@export var attack_anim : AnimationPlayer
@onready var player_collider = $TakenDamageArea
@export var mesh : MeshInstance3D
@export var camera_pivot : Node3D
var mouse_sens = 0.003
var rotation_y = 0.0
const SPEED = 5.0
const JUMP_VELOCITY = 4.5

@onready var area = $Sword2/Area3D
@onready var timer = $Timer

var health = 100

var overlapping_enemies = []

func _ready():
	area.body_entered.connect(_on_body_entered)
	area.body_exited.connect(_on_body_exited)
	player_collider.body_entered.connect(_taken_damage)
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _unhandled_input(event: InputEvent) -> void:
	if event is InputEventMouseMotion:
		# Y ekseninde (sağa-sola) karakteri döndür
		rotate_y(-event.relative.x * mouse_sens)
		# X ekseninde (yukarı-aşağı) kamerayı döndür (Pivot)
		rotation_y -= event.relative.y * mouse_sens
		rotation_y = clamp(rotation_y, deg_to_rad(-90), deg_to_rad(90))
		camera_pivot.rotation.x = rotation_y
	if event is InputEventKey and event.pressed and event.keycode == KEY_ESCAPE:
			get_tree().quit()


func _process(delta: float) -> void:
	if Input.is_action_just_pressed("attack"):
		attack_anim.play("attack")
		for enemy in overlapping_enemies:
			if is_instance_valid(enemy):
				enemy.queue_free()
		overlapping_enemies.clear()  # Listeyi temizle

func _physics_process(delta: float) -> void:
	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * 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_back")
	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)
	print(is_on_floor())
	print(Input.is_action_just_pressed("jump"))
	move_and_slide()


func _on_body_entered(body):
	if body.is_in_group("enemy"):
		overlapping_enemies.append(body)
func _on_body_exited(body):
	if body.is_in_group("enemy"):
		overlapping_enemies.erase(body)
func _taken_damage(player_collider):
	if player_collider.is_in_group("enemy"):
		print("Hasar alındı!")
		health -= 50
		_dead()
func _dead():
	if health <= 0:
		#get_tree().quit()
		pass

Please put your code between ``` at the top and bottom of your code. Right now it’s impossible to read.

i didnt know it. thanks for advice

1 Like

I don’t see anything in your code that would prevent movement after pressing the attack action.