bullet.gd 470 B

1234567891011121314151617181920212223
  1. extends CharacterBody2D
  2. var direction = Vector2()
  3. @export var speed: float = 1000.0
  4. @onready var root = get_tree().root
  5. func _ready():
  6. set_as_top_level(true)
  7. func _physics_process(delta):
  8. if not root.get_visible_rect().has_point(position):
  9. queue_free()
  10. var motion = direction * speed * delta
  11. var collision_info = move_and_collide(motion)
  12. if collision_info:
  13. queue_free()
  14. func _draw():
  15. draw_circle(Vector2(), $CollisionShape2D.shape.radius, Color.WHITE)