33 lines
936 B
GDScript
33 lines
936 B
GDScript
class_name BombEmitter extends Node3D
|
|
|
|
@onready var collision_area : Area3D = $'Area3D'
|
|
|
|
const EXPLOSION_PUSH_SPEED: float = 8
|
|
|
|
var owning_player: Player = null
|
|
var processed = false
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
collision_area.connect("body_entered", on_body_enter)
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _physics_process(_delta):
|
|
if processed:
|
|
queue_free()
|
|
|
|
processed = true
|
|
|
|
func on_body_enter(body: Node3D):
|
|
var player : Player = body as Player
|
|
|
|
if player and player != owning_player:
|
|
var vector_to_player: Vector3 = player.global_position - global_position
|
|
var length: float = vector_to_player.length()
|
|
if length > 0.01:
|
|
print ("Bomb pushes player " + str(player))
|
|
var direction : Vector3 = vector_to_player / length
|
|
player.explosion_influence = 1
|
|
player.explosion_velocity = direction * EXPLOSION_PUSH_SPEED
|