I’m trying to make my bullets be destroyed when they leave the screen, but the function that should teorically do this isn’t working, does someone know why?
extends PhysicsBody2D
class_name projectile
var speed = 300
var velocity = 50
func start(_position, _direction):
rotation = _direction
position = _position
velocity = Vector2(speed, 0).rotated(rotation)
func _process(delta):
print (global.active_bullets)
func _physics_process(delta):
var collision = move_and_collide(velocity * delta)
if collision:
velocity = velocity.bounce(collision.get_normal())
if collision.get_collider().has_method(“hit”):
collision.get_collider().hit()
func _on_visible_on_screen_enabler_2d_screen_exited():
queue_free()
func _on_timer_timeout():
global.active_bullets = 0
queue_free()