How to revive an explosion that removes surrounding bodies?

I'm trying to put a bomb in some place, and when it explodes everything around, it will fly away and the speed depends on how close the object of the bomb is. something like when a black bird explodes with angry birds.

can anyone give me some sample code or a way to do this (I am using andengine with box2d)

Thank you

+6
source share
1 answer

If it is realistic (ish), like Angry Birds, then for every object that is inflated by a bomb, it will follow a quadratic path.

I do not know andengine or box2d. But I did a simple 2d explosion and simulation of shells in the game. I hope you can take some of the following:

You would like to know the coordinate distance (x, y) of the object from the bomb. From this we calculate the angle. (for example, an object above a bomb, when it explodes, will have an angle of 90 or pi / 2.

From this work out a sin and cos angle. Multiply it by a certain force factor F. (depend on the strength of the bomb and the distance from the object from the bomb). From here you have your initial motion vector {F * Math.cos (angle), F * Math.sin (angle)};

Hence, just planar kinematics. The object should follow a quadratic path through the air. The equations may look something like this:

object.setXCoord(object.getXCoord()+time_constant); //after initial explosion, no force is //acting horizontally on object. object.setYCoord(object.getYCoord()-some_constant*time_constant+another_constant*time_constant*time_constant);// note Y path //relative to time is quardatic. 

You may need to add some clips depending on what types you will use. All constants depend on your game. time_constant could very well be 1, but I found that doing the plural of 1 made the explosion more visually appealing. those. when your time counter t increases, the movement of the object can use time_constant 0.5. I used a lot of trial and error to see which constant values ​​work best.

+7
source

Source: https://habr.com/ru/post/894512/


All Articles