0 votes

I have a multiple RigidBody2D “targets” stacked in a pyramid (like Angry Birds) and I’m trying to make an explosion effect so that when the user clicks, the targets within a certain distance of the click position are “blown away” from the click point.

So far my approach is to instance an Explosion scene at the click location which has a CollisionBody2D child and using the on body entered signal I can get a list of the overlapping targets. However I’m now struggling to figure out what value to call addcentralimpulse with to make the overlapping targets “blow away” in the right direction. I think I need to do something with the angle between the centre of the explosion (the mouse click point) and the centre point of the target but I don’t know how to calculate that and if it’s actually the right value to call addcentralimpulse with

Godot version latest
in Engine by (20 points)

1 Answer

0 votes
Best answer

this gives you a vector of length=1 in the direction explosion-object

you can then multiply it to the strenght of the explosion and maybe divide it by the distance of the explosion object

force= strength*direction/(object.position-explosion.position).length()
by (1,500 points)
selected by

Nice! That works perfectly in terms of direction. Just need to play around with the weight and base force value to get a good impact. Thanks!!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.