#Project crashes on launch when NPC exists
1 messages · Page 1 of 1 (latest)
Did you check the logs and/or the console?
Most of the time, this is due to an infinite loop or (more rarely) due to a corrupted resource.
Do you have version control set up?
Also try to press F7 as it is booting up to pause execution and see what part of the code it is stuck in.
f7 isn't doing anything, it crashes all the same
we're looking in output when it starts, nothing even happens
Output may be different from the logs.
But if anything, launch godot with the --verbose parameter
this is all im getting
I HAVE FOUND THE BUG
for some reason, the game cannot run the function pick_random_direction() during ready or it crashes
var speed = 50
var last_direction = Vector2.ZERO
var animated_sprite
var direction_change_timer = 0
var direction_change_interval = 5
# intended to define area patrolled by the enemy
var min_position = Vector2(0, 0)
var max_position = Vector2(300, 300)
@export var max_x_distance : int = 300
@export var max_y_distance : int = 300
func _ready():
animated_sprite = $AnimatedSprite2D
pick_random_direction()
func _physics_process(delta):
direction_change_timer += delta
if direction_change_timer >= direction_change_interval:
pick_random_direction()
direction_change_timer = 0
velocity = last_direction * speed
#reset flips for the sprite
animated_sprite.flip_h = false
animated_sprite.flip_v = false
if last_direction.x != 0:
animated_sprite.play("move_left")
animated_sprite.flip_h = last_direction.x > 0
elif last_direction.y < 0:
animated_sprite.play("move_up")
elif last_direction.y > 0:
animated_sprite.play("move_down")
move_and_slide()
var old_position = position
position.x = clamp(position.x, min_position.x, max_position.x)
position.x = clamp(position.y, min_position.y, max_position.y)
if old_position != position:
#reverse by 180 degrees if the enemy hits a boundary
last_direction = -last_direction
func pick_random_direction():
var new_direction = Vector2.ZERO
#ensure direction is never a zero vector
#most of these comments are lifted wholesale from the tutorial btw, just for the record.
while last_direction == Vector2.ZERO:
new_direction = Vector2(randi() % 3 - 1, randi() % 3 - 1)
new_direction = new_direction.normalized()
last_direction = new_direction```
can yall find any reason why this might be broken?
That def. looks like an engine bug.
Specially with the lack of error.
Maybe it is due to the lack of type-casting?
Issues with that kind of stuff is harder to detect
so, we found something weird.
this only happens if "pick_random_direction()" is part of _ready
something about running that specific function on ready breaks the entire engine