Skip to content

Conversation

iobaixas
Copy link

Adds the set_velocity method and velocity property to the FmodEventEmitter3D node. This enables the doppler effect for spatialized audio.

Proposed usage:

extends RigitBody3D

@export emitter: FmodEventEmitter3D

func _physics_process(delta: float) -> void:
	emitter.set_velocity(linear_velocity)

Changes

  • Adds FmodEventEmitter3D.set_velocity, FmodEventEmitter3D.get_velocity and FmodEventEmitter3D.velocity. Internally calls the get_3d_attributes_from_transform3d method that already supported a velocity parameter.
  • Adds some checks to the FModEventEmitter.h file to prevent crashes when binding an event for the first time in the editor. Im not sure that all the checks are necessary, but it solves the issue. Requires further testing and maybe could be moved to a different PR.

This method allows to report velocity to the fmod API to enable doppler effect for spatialized audio
@CedNaru CedNaru requested review from piiertho and CedNaru August 27, 2025 13:38
@CedNaru
Copy link
Member

CedNaru commented Aug 27, 2025

Thank for the proposal.
It's indeed a low hanging fruit we forgot to implement despite setting up the maths for it.
I have a few changes to request:

  • We want to keep parity between 2D and 3D so if the velocity is added to the 3D emitter, then it should be added to the 2D ones.
  • Setting velocity directly on the node is okay but probably too low level, it would be better to be directly on the FmodEvent class. Instead the Emitter Node could take a NodePath to a PhysicBody and use it internally to extract the velocity.
  • Can you clarify things about those crashes when setting an event in the editor? Those checks are welcome but as it's not directly related, it should be in a separate PR so each are easier to review.

Copy link
Member

@piiertho piiertho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the proposal !

void _notification(int p_what);
virtual void _exit_tree() override;

void set_velocity(const Vector3& velocity);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be added to FmodEventEmitter template by adding a vector template param to it.
This way it will be implemented for both 2D and 3D emiters.

@iobaixas
Copy link
Author

I'll move the crash related changes to a different PR and add more details about the crashes there.

I'll also give it a shot at setting the velocity for the 2D node using a vector template param.

About the emitter tracking another node. I think it does not match the current 'emitter reporting its own position' behavior. Maybe keep the set_velocity method, as it refers to an emitter own property, like its position, and add another mode for the emitter where it tracks both position and velocity of a given physics node?

@CedNaru
Copy link
Member

CedNaru commented Aug 27, 2025

When setting the velocity manually, the emitter is not really reporting its own speed either because the data must come from a different source that is set in the script.
The goal behind those nodes is for them to be as autonomous as possible without script by setting properties in the inspector.

Being a Node2D/3D it has a proper position, but to have its own velocity we would have to make it a physic body, which would create other problems. So the simplest approach would be to set a PhysicBody node the emitter can track automatically every frame. It would remain optional and not setting a tracked node would give the same behavior we have today (no doppler effect).
Setting the velocity manually would still be possible by script using the lower level FmodEvent the node wraps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants