1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-25 09:04:19 +00:00
swear-jar/noise/noisy.gd

27 lines
906 B
GDScript3
Raw Normal View History

2023-10-24 22:02:38 +00:00
extends Node
class_name Noisy
@export var type: StringName
@onready var target: RigidBody2D = get_parent()
func _on_body_entered(body: Node):
var other_noisy: Node = body.find_child("Noisy")
# If both bodies are noisy...
if other_noisy:
# Find our sounds...
var sounds_contact: Array[Node] = self.find_children("*", "SoundContact", false)
for sound_contact in sounds_contact:
# Check if the type matches...
if sound_contact.type == other_noisy.type:
# Determine the collision strength
var collision_normal = (body.position - target.position).normalized()
var this_velocity_on_normal = target.linear_velocity.dot(collision_normal)
var other_velocity_on_normal = -body.linear_velocity.dot(collision_normal)
var velocity_on_normal = this_velocity_on_normal + other_velocity_on_normal
if sound_contact.min_velocity <= velocity_on_normal:
sound_contact.play()