Making characters stop when talking

I am using godot 4.4

Question

So I am using the dialouge manager plugin. and after trying everything I am unable to have the NPC’s stop moving when they are talking with the player then continue moving after they are done talking. I have a project due in a week and I need help figuring this out. I am a very VERY roomy coder. here is my player and NPC script

PLAYER: extends CharacterBody2D

@export var MAX_SPEED = 200
@export var ACCELERATION = 1500
@export var FRICTION = 1200

@onready var sprite = $AnimatedSprite2D
@onready var face = $AnimatedSprite2D/face

var axis = Vector2.ZERO
var can_move: bool = true
var is_portrait_mode: bool = false

func _ready():
Input.is_joy_known(0)
add_to_group(“player”)

func _physics_process(delta):
if can_move:
move(delta)
update_sprite_and_face()

func get_input_axis():
axis.x = int(Input.is_action_pressed(“move_right”)) - int(Input.is_action_pressed(“move_left”))
axis.y = int(Input.is_action_pressed(“move_down”)) - int(Input.is_action_pressed(“move_up”))
return axis.normalized()

func move(delta):
axis = get_input_axis()

if axis == Vector2.ZERO:
	apply_friction(FRICTION * delta)
else:
	apply_movement(axis * ACCELERATION * delta)

move_and_slide()

func apply_friction(amount):
if velocity.length() > amount:
velocity -= velocity.normalized() * amount
else:
velocity = Vector2.ZERO

func apply_movement(accel):
velocity += accel
velocity = velocity.limit_length(MAX_SPEED)

func update_sprite_and_face():
if velocity.x < 0:
sprite.flip_h = true
face.position.x = -67.892
elif velocity.x > 0:
sprite.flip_h = false
face.position.x = -38.462

if velocity.length() > 0:
	var sway = sin(Time.get_ticks_msec() * 0.005) * 0.15
	sprite.rotation = sway
else:
	sprite.rotation = 0

func set_can_move(state: bool) → void:
can_move = state
if !can_move:
velocity = Vector2.ZERO
axis = Vector2.ZERO
NPC: extends CharacterBody2D

enum Gender { MALE, FEMALE }

NPC Movement states

enum MovementState { MOVING, IDLE, WANDERING, WALL_PAUSE }

Reference to the NPC Manager

var npc_manager

Export variables for inspector

var role: String

Player interaction cooldown

@export var PLAYER_COOLDOWN_MIN = 5.0
@export var PLAYER_COOLDOWN_MAX = 20.0
var player_interaction_cooldown: float = 0.0

NPC state

var can_move: bool = true
var npc_name: String
var gender: Gender
var hair_style: String

Movement state

var current_state = MovementState.MOVING
var movement_direction: Vector2 = Vector2.ZERO
var target_direction: Vector2 = Vector2.ZERO
var state_timer: float = 0.0
var current_state_duration: float = 0.0
var wander_point: Vector2 = Vector2.ZERO
var initial_position: Vector2 = Vector2.ZERO
var current_facing: float = 0.0
var sprite_direction: int = 1
var previous_direction: Vector2 = Vector2.ZERO

Camera variables

var camera = null
var tween = null
var is_portrait_mode: bool = false
@onready var sprite = $AnimatedSprite2D
@onready var hair_sprite = $AnimatedSprite2D/Hair
@onready var face = $AnimatedSprite2D/face
@onready var player_interaction_shape = $Player_Interaction/Player_Interaction_Area

Constants for appearance (moved from GameState)

const MALE_NAMES = [“James”, “John”, “Michael”, “William”, “David”]
const FEMALE_NAMES = [“Mary”, “Patricia”, “Jennifer”, “Linda”, “Elizabeth”]
const MALE_HAIR_STYLES = [
“res://Assets/Characters/NPC/Hair/male/Hair 1M (black).png”,
“res://Assets/Characters/NPC/Hair/male/Hair 1M (brown).png”
]
const FEMALE_HAIR_STYLES = [
“res://Assets/Characters/NPC/Hair/female/Hair 1 (gold).png”,
“res://Assets/Characters/NPC/Hair/female/Hair 1 (grey).png”
]

func _ready():
randomize()

# Get the NPC_Manager node from the scene tree
# Try different paths depending on your scene structure
npc_manager = get_node_or_null("/root/NPC_Manager")  # If it's an autoload

if npc_manager == null:
	# Try to find it in the current scene
	npc_manager = get_node_or_null("../NPC_Manager")

if npc_manager == null:
	# Last resort - create an instance
	npc_manager = load("res://Scripts/NPC_Manager.gd").new()
	add_child(npc_manager)

initialize_npc()
initial_position = position
choose_new_state()
add_to_group("npcs")

# Find the camera
camera = get_viewport().get_camera_2d()
if !camera:
	push_error("Camera2D not found in the scene!")

# Ensure the player interaction area exists
if !player_interaction_shape:
	push_error("PlayerInteractionArea node not found! Add a CollisionShape2D named PlayerInteractionArea as child")

func _physics_process(delta):
npc_manager.process_npc(self, delta)
update_sprite_animation()

Appearance management functions (moved from GameState)

func get_random_name(gender_enum: int) → String:
var names = MALE_NAMES if gender_enum == Gender.MALE else FEMALE_NAMES
return names[randi() % names.size()]

func get_random_hair_style(gender_enum: int) → String:
var styles = MALE_HAIR_STYLES if gender_enum == Gender.MALE else FEMALE_HAIR_STYLES
return styles[randi() % styles.size()]

func initialize_npc():
gender = Gender.values()[randi() % Gender.size()]
npc_name = get_random_name(gender)
hair_style = get_random_hair_style(gender)
role = GameState.get_available_role() # Get an unassigned role

print("NPC Initialized: ", npc_name, " - Role: ", role)
update_appearance()

func interact_with_player():
# Set the current NPC name in GameState before showing dialogue
GameState.set_current_npc_name(npc_name)

# Get the dialogue resource based on role
var role_data = GameState.get_role_data(role)
var dialogue_resource = load(role_data.dialogue_file)

# Show the dialogue balloon
if dialogue_resource:
	DialogueManager.show_dialogue_balloon(dialogue_resource, "start")
else:
	push_error("Failed to load dialogue resource: " + role_data.dialogue_file)

Please write your codes in performatted text format in the forum. Just select your all codes and press CTRL+E but it would cause tab problem so consider to do like this:

``` Paste your codes within these symbols ```
extends CharacterBody2D

@export var MAX_SPEED = 200
@export var ACCELERATION = 1500
@export var FRICTION = 1200

@onready var sprite = $AnimatedSprite2D
@onready var face = $AnimatedSprite2D/face

var axis = Vector2.ZERO
var can_move: bool = true
var is_portrait_mode: bool = false

func _ready():
	Input.is_joy_known(0)
	add_to_group("player")

func _physics_process(delta):
	if can_move:
		move(delta)
		update_sprite_and_face()

func get_input_axis():
	axis.x = int(Input.is_action_pressed("move_right")) - int(Input.is_action_pressed("move_left"))
	axis.y = int(Input.is_action_pressed("move_down")) - int(Input.is_action_pressed("move_up"))
	return axis.normalized()

func move(delta):
	axis = get_input_axis()
	
	if axis == Vector2.ZERO:
		apply_friction(FRICTION * delta)
	else:
		apply_movement(axis * ACCELERATION * delta)
	
	move_and_slide()

func apply_friction(amount):
	if velocity.length() > amount:
		velocity -= velocity.normalized() * amount
	else:
		velocity = Vector2.ZERO

func apply_movement(accel):
	velocity += accel
	velocity = velocity.limit_length(MAX_SPEED)

func update_sprite_and_face():
	if velocity.x < 0:
		sprite.flip_h = true
		face.position.x = -67.892
	elif velocity.x > 0:
		sprite.flip_h = false
		face.position.x = -38.462
	
	if velocity.length() > 0:
		var sway = sin(Time.get_ticks_msec() * 0.005) * 0.15
		sprite.rotation = sway
	else:
		sprite.rotation = 0

func set_can_move(state: bool) -> void:
	can_move = state
	if !can_move:
		velocity = Vector2.ZERO
		axis = Vector2.ZERO

extends CharacterBody2D

enum Gender { MALE, FEMALE }
# NPC Movement states
enum MovementState { MOVING, IDLE, WANDERING, WALL_PAUSE }
# Reference to the NPC Manager
var npc_manager
# Export variables for inspector
var role: String
# Player interaction cooldown
@export var PLAYER_COOLDOWN_MIN = 5.0
@export var PLAYER_COOLDOWN_MAX = 20.0
var player_interaction_cooldown: float = 0.0
# NPC state
var can_move: bool = true
var npc_name: String
var gender: Gender
var hair_style: String
# Movement state
var current_state = MovementState.MOVING
var movement_direction: Vector2 = Vector2.ZERO
var target_direction: Vector2 = Vector2.ZERO
var state_timer: float = 0.0
var current_state_duration: float = 0.0
var wander_point: Vector2 = Vector2.ZERO
var initial_position: Vector2 = Vector2.ZERO
var current_facing: float = 0.0
var sprite_direction: int = 1
var previous_direction: Vector2 = Vector2.ZERO
# Camera variables
var camera = null
var tween = null
var is_portrait_mode: bool = false
@onready var sprite = $AnimatedSprite2D
@onready var hair_sprite = $AnimatedSprite2D/Hair
@onready var face = $AnimatedSprite2D/face
@onready var player_interaction_shape = $Player_Interaction/Player_Interaction_Area

# Constants for appearance (moved from GameState)
const MALE_NAMES = ["James", "John", "Michael", "William", "David"]
const FEMALE_NAMES = ["Mary", "Patricia", "Jennifer", "Linda", "Elizabeth"]
const MALE_HAIR_STYLES = [
	"res://Assets/Characters/NPC/Hair/male/Hair 1M (black).png",
	"res://Assets/Characters/NPC/Hair/male/Hair 1M (brown).png"
]
const FEMALE_HAIR_STYLES = [
	"res://Assets/Characters/NPC/Hair/female/Hair 1 (gold).png",
	"res://Assets/Characters/NPC/Hair/female/Hair 1 (grey).png"
]

func _ready():
	randomize()
	
	# Get the NPC_Manager node from the scene tree
	# Try different paths depending on your scene structure
	npc_manager = get_node_or_null("/root/NPC_Manager")  # If it's an autoload
	
	if npc_manager == null:
		# Try to find it in the current scene
		npc_manager = get_node_or_null("../NPC_Manager")
	
	if npc_manager == null:
		# Last resort - create an instance
		npc_manager = load("res://Scripts/NPC_Manager.gd").new()
		add_child(npc_manager)
	
	initialize_npc()
	initial_position = position
	choose_new_state()
	add_to_group("npcs")
	
	# Find the camera
	camera = get_viewport().get_camera_2d()
	if !camera:
		push_error("Camera2D not found in the scene!")
	
	# Ensure the player interaction area exists
	if !player_interaction_shape:
		push_error("PlayerInteractionArea node not found! Add a CollisionShape2D named PlayerInteractionArea as child")

func _physics_process(delta):
	npc_manager.process_npc(self, delta)
	update_sprite_animation()

# Appearance management functions (moved from GameState)
func get_random_name(gender_enum: int) -> String:
	var names = MALE_NAMES if gender_enum == Gender.MALE else FEMALE_NAMES
	return names[randi() % names.size()]

func get_random_hair_style(gender_enum: int) -> String:
	var styles = MALE_HAIR_STYLES if gender_enum == Gender.MALE else FEMALE_HAIR_STYLES
	return styles[randi() % styles.size()]

func initialize_npc():
	gender = Gender.values()[randi() % Gender.size()]
	npc_name = get_random_name(gender)
	hair_style = get_random_hair_style(gender)
	role = GameState.get_available_role()  # Get an unassigned role

	print("NPC Initialized: ", npc_name, " - Role: ", role)
	update_appearance()

func interact_with_player():
	# Set the current NPC name in GameState before showing dialogue
	GameState.set_current_npc_name(npc_name)
	
	# Get the dialogue resource based on role
	var role_data = GameState.get_role_data(role)
	var dialogue_resource = load(role_data.dialogue_file)
	
	# Show the dialogue balloon
	if dialogue_resource:
		DialogueManager.show_dialogue_balloon(dialogue_resource, "start")
	else:
		push_error("Failed to load dialogue resource: " + role_data.dialogue_file)

func _exit_tree():
	# Release the role when the NPC is removed from the scene
	GameState.release_role(role)
	
	# Unregister this NPC
	GameState.unregister_npc(get_instance_id())

# Visual Updates
func update_sprite_animation():
	if abs(velocity.x) > 5:
		var new_direction = 1 if velocity.x > 0 else -1
		if new_direction != sprite_direction:
			sprite_direction = new_direction
			update_sprite_flip()
	
	if velocity.length() > 0:
		var movement_intensity = clamp(velocity.length() / npc_manager.MAX_SPEED, 0, 1)
		var sway = sin(Time.get_ticks_msec() * 0.005) * 0.15 * movement_intensity
		sprite.rotation = sway
	else:
		sprite.rotation = lerp(sprite.rotation, 0.0, 0.1)

func update_sprite_flip():
	sprite.flip_h = sprite_direction < 0
	hair_sprite.flip_h = sprite_direction < 0
	face.position.x = -67.892 if sprite_direction < 0 else -38.462

func update_appearance():
	if hair_sprite:
		var hair_texture = load(hair_style)
		if hair_texture:
			hair_sprite.texture = hair_texture
		else:
			print("Failed to load hair texture: ", hair_style)
	else:
		print("Hair sprite node not found!")

# Helper function to call npc_manager
func choose_new_state():
	npc_manager.choose_new_state(self)

please help