Apply impulse to all bodies

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By timoschwarzer
:warning: Old Version Published before Godot 3 was released.

Hello there!

Is it possible to apply a radial impulse to all bodies near a global position?
Or do I have to manually calculate impulse vectors one by one for each active body in my scene near to that specific position?

Thanks in advance,
TImo

:bust_in_silhouette: Reply From: Zylann

I’m not aware of a built-in function doing that. I think that calculating the vectors for each body inside the “force field” would do the trick. I would query a circular area for bodies in _fixed_process() and apply the force on them.

Hmm, I don’t get the logic behind apply_impulse()
Are the coordinates local and where is which vector applied?

timoschwarzer | 2016-06-29 21:12

As the doc says:

void apply_impulse( Vector2 pos, Vector2 impulse )
Apply a positioned impulse (which will be affected by the body mass and shape). This is the equivalent of hitting a billiard ball with a cue: a force that is applied once, and only once.

So the position parameter is local, and the function must be applied once (for example, an explosion, or a billiard ball hit)

Zylann | 2016-06-30 18:48