Godot Version
4.6.2
Question
Hello!!
So i have a sprite showing up when a player interacts with a chest. There are two chests in the scene, so i made two identical sprites. At first i had this code, which did work, and now works for everything else except locking the players movement:
extends Sprite2D #second pop up (although i coded it first, copy and pasted the code into the other script but changed the connections)
@onready var player = $"../CharacterBody2D"
@onready var c = $"../Chest2"
@onready var timer = $"../Timer2"
func _ready():
visible = false
func _process(delta: float) -> void:
if c.key_got_1:
print("key_got_one")
if c.key_shown_1:
show_got()
if visible == true:
player.locked = true
if visible == false:
player.locked = false
func _on_timer_2_timeout() -> void:
visible = false
func show_got():
visible = true
timer.start()
c.key_shown_1 = false
print("show_got_1")
And then added the next sprite, with this code, that fully works:
extends Sprite2D #sprite for first pop up, connected to everything needed
@onready var player = $"../CharacterBody2D"
@onready var c = $"../Chest"
@onready var timer = $"../Timer"
func _ready():
visible = false
func _process(delta: float) -> void:
if c.key_got:
if c.key_shown:
show_got()
if visible == true:
player.locked = true
if visible == false:
player.locked = false
func show_got():
visible = true
timer.start()
c.key_shown = false
func _on_timer_timeout() -> void:
visible = false
But now, while the second one i put up is working, the first one is not anymore. I know its running the function, and while everything else is working, I cant get the player to lock their movements for the first one. Any ideas? Did i miss something obvious because ive just been looking at it too long lol? thanks in advance!!
(heres the player movement locking script as well)
func _physics_process(delta: float) -> void:
if locked == false:
var direction = Input.get_vector("left_arrow", "right_arrow", "up_arrow", "down_arrow")
velocity = direction * max_speed
move_and_slide()
if locked:
pass