extends RigidBody3D

var grabbable : bool = true
@export var damage : float = 6.0
@export var min_damaging_velocity : float = 1.0

func _ready():
	contact_monitor = true
	max_contacts_reported = 2
	set_collision_mask_value(2, true)
	body_entered.connect(_on_body_entered)

func _on_body_entered(body):
	if body.get("shootable") == true:
		var totalvelocity = abs(angular_velocity.x + angular_velocity.y + angular_velocity.z)
		if totalvelocity > (3 * min_damaging_velocity):
			if body.get("rootnode") == true:
				body.deal_damage(totalvelocity * damage)
			else:
				body.owner.deal_damage(totalvelocity * damage)
			apply_central_impulse(body.position.direction_to(position) * -3.0)
