Godot Version
4.3.stable
Question
Hi, still on my first week with godot. I’ve a basic interaction script between player and door. I’m trying to pause the player’s movement once the input for interaction is triggered, then resume movement if they select “No”.
How can I do this? My code for the door script is below. I’ve tried something like set_physics_process(false) in the If statement but I don’t think I’m using it right.
Help is appreciated, thank you.
extends StaticBody2D
var near_door = false
var want_to_exit = false
var player_talking = false
@onready var leaving = $Leaving
# Called when the node enters the scene tree for the first time.
func _ready():
leaving.visible = false
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if near_door && Input.is_action_just_pressed("interact"):
leaving.visible = true
if Input.is_action_just_pressed("yes"):
get_tree().change_scene_to_file("res://Scenes/main.tscn")
elif Input.is_action_just_pressed("no"):
leaving.visible = false
print("player does not want to leave yet")
func _on_exit_body_entered(body):
if body is CharacterBody2D:
near_door = true
print("player is at the door")
func _on_exit_body_exited(body):
if body is CharacterBody2D:
near_door = false
print("player walked away from the doors")
player code
extends CharacterBody2D
class_name Player
const SPEED = 600
@onready var player = self
@onready var _animated_sprite = $AnimatedSprite2D
func _ready():
add_to_group("player")
# make character move
func _physics_process(delta):
var direction= Input.get_vector("move_left","move_right","move_up","move_down")
velocity = direction * SPEED
move_and_slide()
if Input.is_action_pressed("move_left"):
_animated_sprite.play("move_left")
elif Input.is_action_pressed("move_down"):
_animated_sprite.play("move_down")
elif Input.is_action_pressed("move_up"):
_animated_sprite.play("move_up")
elif Input.is_action_pressed("move_right"):
_animated_sprite.play("move_right")