Godot Version
4.4
Question
How do I get the enemy to stop stuttering when the player goes sideways or next to walls?
What’s going on with the pathing?
heres the code:
class_name Pathing
unc enemy_target_pathing() -> Array:
var enemy_path = character.grid.find_path(
character.map_size.local_to_map(character.global_position),
character.map_size.local_to_map(character.player.global_position)
)
return enemy_path
func enemy_walk() -> void:
if character.current_id_path.is_empty():
character.animation_direction("idle")
return
if not is_moving:
character.target_position = character.map_size.map_to_local(character.current_id_path.front())
is_moving = true
character.global_position = character.global_position.move_toward(character.target_position, MOVESPEED)
if character.global_position == character.target_position:
character.current_id_path.pop_front()
if character.current_id_path.is_empty():
character.animation_direction("idle")
is_moving = false
else:
character.target_position = character.map_size.map_to_local(character.current_id_path.front())
directions(character.global_position, character.target_position)
character.animation_direction("walk")
class_name Enemy
extends Character
@onready var player: Player = %Player
var target_pos: Array
func states_start_turn() -> void:
target_pos = pathing.enemy_target_pathing()
state_machine.change_state(states_chase)
print("")
print("enemy played turn")
func states_chase() -> void:
if target_pos.size() == 1:
return
current_id_path = [target_pos[1]]
pathing.enemy_walk()
if global_position == target_position:
state_machine.change_state(states_idle)
thats basically all the navigation code. But there is also a Astargrid2d