road-rage-tank/player/projectile/player_projectile.gd

30 lines
596 B
GDScript

class_name PlayerProjectile
extends Area3D
const SPEED := 20.
var _initialized := false
var velocity: Vector3
var health: int = 1:
set(v):
health = v
if v == 0:
queue_free()
func _on_collision(node: Node3D):
if node.has_method("hit"):
if node.hit(self):
health -= 1
func _ready() -> void:
body_entered.connect(_on_collision)
area_entered.connect(_on_collision)
func init(dir: Vector3) -> void:
_initialized = true
velocity = dir * SPEED
func _physics_process(delta: float) -> void:
position += velocity * delta
func _process(_delta: float) -> void:
assert(_initialized)