gdquest-2d-project-start/bullet.gd

22 lines
431 B
GDScript

extends Area2D
const SPEED = 1000
const RANGE = 1200
var travelled_distance = 0
func _physics_process(delta):
# Current direction the bullet is facing.
var direction = Vector2.RIGHT.rotated(rotation)
position += direction * SPEED * delta
travelled_distance += SPEED * delta
if travelled_distance > RANGE:
queue_free()
func _on_body_entered(body):
queue_free()
if body.has_method("take_damage"):
body.take_damage()