Trouble with handling drop impact sfx

Godot Version

v4.7.2

Context

For context I’m trying to do a project similiar to 2017 mobile horror game Granny. The main gimmick in that game was the fact that every physical object made a sound when dropped. I thought it would be pretty easy to replicate and that’s how it seemed at first, but then very annoying problem appeared.

The Problem

The problem is that sometimes, when rigid body is dropped, sound just doesn’t play. I checked the _on_body_entered function first and it works fine, so its not a problem with collision but instead a problem with velocity accaunting on impact.

example ingame:

Tree and code

drop_audio_emitter code:

extends Area3D

@export_range(0.0, 2.0, 0.1) var velocity_threshold := 1.0
var _parent: RigidBody3D

func _ready() -> void:
  var parent: Node3D = get_parent()
  if parent is RigidBody3D:
    _parent = parent
    
    # ...
    
    body_entered.connect(_on_body_entered)
  else:
    push_error("Parent is not a RigidBody3D, can't function without it!")

func _on_body_entered(_body: Node3D) -> void:
  if not _parent.freeze and (_parent.linear_velocity.length() > velocity_threshold or _parent.angular_velocity.length() > velocity_threshold):
    _play_audio()

I know that the problem here is with the calculation but i genuinely don’t know what else could be used here because there’s almost no information about how to do that kind of stuff, and the one tutorial I found used pretty much the same method as I am.

P.S. Area3D is used instead of RigidBody3D’s contact monitor mainly because with a separate area node it’s easier making only one part of the object make sound. and also lowering the velocity threshold doesn’t really work

Did you check the warning on your “drop_audio_emitter” node?

If you print the linear velocity length, what is the value?

I believe your issue, as you might’ve stated yourself, is caused by the fact that once the body (or Area3D in your case) reports a collision, the linear_velocity has already been corrected.

The simplest way to solve this issue is to store a history of the body’s state (transform, velocity etc.). The old value(s) can then be referenced when the collision occurs.

I already made a solution before that works this way. You can view it here.
The important part of the code:

# === Incomplete code snippet taken from the solution in the post linked above ===

# State history
var transform_old: Transform2D
var velocity_old: Vector2
var angular_velocity_old: float
# NOTE: For extended use, it would be best to wrap this kind of data in a class

# [...]

var collision_velocity = compute_velocity_at_point(to_collision_point, state, transform_old, velocity_old, angular_velocity_old)

if (collision_velocity.length() >= effect_speed_threshold):
	# Spawn, position and play the particle instance

You might need to alter either the posted solution or your own system. The solution in the post makes use of _integrate_forces() which provides a state variable that lets you access collision data. Since you’re using an Area3D to process the collision, you may find it more difficult to be precise – you’ll figure this out as you go.

Moreover, depending on how tight the Area3D’s shape fits the RigidBody3D’s shape, you may be experiencing a different issue. If you would, could you provide an image of the physics configuration of the object in question?


If you have any questions regarding this, feel free to ask them here.