so it now prints out the bodies, my layers where correct.
i dont understand i need to put the code in physics process, and cant just call it from a func.
however the apply impulse code is wrong, just like @spacecloud said, what should go there?
extends Node3D
@export var area : Area3D
@export var force = 5.0
const EXPLOSION_TIME = 0.5
var explosion_timer = 0.0
var exploded = false
func _ready():
set_physics_process(false)
func addexplosionforce():
set_physics_process(true)
print("didexplode")
exploded = true
func _physics_process(delta):
if not is_instance_valid(area):
return
for body in area.get_overlapping_bodies():
if body is RigidDynamicBody3D:
print(body.name)
var direction_vector = body.global_transform.origin - area.global_transform.origin
var distance = direction_vector.length()
var collision_force = (force / distance) * body.mass
body.apply_impulse(Vector3.ZERO, direction_vector.normalized() * collision_force)
if exploded:
explosion_timer += delta
if explosion_timer >= EXPLOSION_TIME:
area.monitoring = false
area.queue_free()
func _on_visible_on_screen_notifier_3d_screen_exited():
self.queue_free()