Positional and directional AudioNode with RigidBodyControl

Hi

I am trying to find the right way, to move and transform a positional and directional AudioNode together with e.g. a Sphere which is controlled by a RigidBodyControl. I could put both, the AudioNode and the Sphere, into a new parent Node and move the RigidBodyControl from the Sphere to this Node. Or is there a better way?

TIA

That’s the “scene graph” way, though.

Is there a reason that you don’t want to use the scene graph to solve a problem like this?

1 Like

is there a better way?

Your way seems good to me.

1 Like

Yeah the way you described would work perfectly fine.

Not necessarily better, but there is another way that could be more or less useful depending on the situation.

You can do it the way you mentioned by attaching the AudioNode to the RigidBodyControl’s node so it automatically follows that node.
Or you could attach the audioNode directly to the rootNode and call audioNode.setLocalTranslation(rigidBodyControl.getPhysicsLocation()); in the update loop every frame.

The only difference here is that the audioNode would not be affected by the rigidBodyControl’s rotation or scale if you do it the second way since its no longer directly attached to it.

1 Like

If someone does it this way then they also have to do the careful dance of hooking the right point of update or the audio node location will lag the rigid body by one frame.

Better to just use the scene graph for what it’s there for.

3 Likes

No, I would like to use the scene graph.

The reason for my question was, that there is some logic in RigidBodyControl which selects the correct collision shape automatically based on the spatial. So I was not sure, whether moving the RigidBodyControl from a Sphere (Geometry) to a Node would influence the collision shape.

1 Like

If not specified in the constructor, the collision shape for a RigidBodyControl is auto-generated when the control is added to a Spatial.

Moving the control up one level in the scene-graph does change the auto-generated collision shape in some cases: for instance, if the child has a non-identity local transform. There is also a special case when the Spatial is a geometry with a spherical mesh, in which case the control auto-generates a SphereCollisionShape instead of a mesh or hull shape.

If you specifically want a SphereCollisionShape for the rigid body, then the workaround would be to explicitly construct the shape you want and pass it to the RigidBodyControl constructor.

1 Like