RadialImpulse
August 15, 2024

This plugin brings two new nodes, RadialImpulse2D and RadialImpulse3D. Both of them will apply an impulse to each rigid body that is within radius, away from the RadialImpulses center.

Why

One possible use case is to attach this into a projectile node. When it collides with something, request the RadialImpulse to apply the impulse into all rigid bodies within radius. This might result in something resembling an explosive effect.

The animation bellow showcases the RadialImpulse2D in action. Within it there is one visual "hint" that showcases the moment a mouse click occurs. That is the moment the impulse is applied within the area.

Usage

The basic usage of this plugin is like this:

  1. Attach the relevant (2D or 3D) RadialImpulse node into the scene.
  2. Setup its properties like radius, impulse value (which appears as Force in the Inspector), falloff and physical layers.
  3. Call the node's apply_impulse() function whenever it's required/desired that it applies the impulse into the rigid bodies in radius.

That's it!

OK, for some more explanation. Note that the apply_impulse() function does not receive any parameter. Indeed, it uses the values set within the node's properties.

I believe the radius and force are pretty self explanatory. The falloff might need some explanation. It offers two modes that will determine the actual impulse value applied to the nodes.

When the radial impulse node is selected, one of the property categories is the Collision. It behaves exactly like any other physical object in the Godot engine. To be more specific, detection of rigid bodies is performed by a collision shape. The layers exposed are directly applied into that shape.

Radial Impulse - Inspector

Other

There are two limitations that must be mentioned here.

The first I want to discuss will be depicted by a 2D drawing, however it applies to both 2D and 3D. The limitation in question relates to a specific situation that will result in the RadialImpulse either applying the impulse inaccurately or completely missing the rigid body that is indeed within radius.

That said, consider the image bellow. The circle represents the RadialImpulse and its acting area (controlled by the radius). The two rectangles represents two rigid bodies. Each rectangle has its "center of mass" depicted by a dot.

Limitation

In a situation like this, it's expected that both rectangles would start to spin after having the impulse applied to them. However that's not what happens. The important aspect here is that the impulse will always be applied into the "center of mass" of the detected rigid body.

But there is another thing. If the falloff mode is set to linear then the rectangle above will not receive any force. Notice that the rectangle in question has its "center" outside of the radius. Because in this falloff mode the force becomes 0 at radius distance, the effect is that the rectangle will not get any impulse applied at all. However the rectangle that appears bellow has its center inside of the affecting circle so it will receive an impulse.

Unfortunately I still don't have a solution to this issue.

The second limitation is related to the node lifetime. Notice at the top of this page that I have mentioned one possible use case for the RadialImpulse, which is to attach it into a projectile then call the apply_impulse() when there is an impact. However there is one aspect here that the projectile will probably be destroyed as soon as it impacts something, also destroying the RadialImpulse.

This situation might result in the impulse not being applied at all. What happens is that this node internally needs to sort of "wait" until the physics is properly updated otherwise it will not correctly detect the rigid bodies. Depending on the situation even a call_deferred() might not help with the projectile destruction.

All is not lost, however. The RadialImpulse has a signal called impulse_applied. Using this signal a few changes can be performed in the projectile's script:

  1. Listen to the impulse_applied signal and in the handler effectively destroy the projectile node.
  2. In the impact handling, instead of destroying the projectile, hide its visual representation and request the impulse to be applied.

And that's it! Second limitation is dealt with!