如何制作将周围物体炸飞的爆炸动画?

发布于 2024-11-28 09:31:38 字数 137 浏览 1 评论 0原文

我试图在某个地方放置一颗炸弹,当它爆炸时,它周围的所有东西都会飞走,速度取决于物体与炸弹的距离。 就像《愤怒的小鸟》中黑鸟爆炸一样。

谁能给我一个示例代码或一种方法(我正在将 andengine 与 box2d 一起使用)

谢谢

I am trying to put a bomb in some place and when it explodes every thing around it will fly away and the speed depends on how close the object to the bomb.
something like when the black bird explodes in angry birds.

can any one give me a sample code or a way to do that (I am using andengine with box2d)

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白云悠悠 2024-12-05 09:31:38

如果它是现实的,就像《愤怒的小鸟》一样,那么对于每个被炸弹炸毁的物体,它将遵循一条二次路径。

我不知道andengine 或box2d。但我在游戏中做了简单的二维爆炸和射弹建模。
我希望您能从以下内容中得到一些信息:

您想找出物体与炸弹的 (x,y) 坐标距离。由此计算角度。 (例如,炸弹上方的物体爆炸时的角度为 90 或 pi/2。

由此计算出该角度的正弦和余弦。将其乘以某个力因子 F。(取决于炸弹的强度和距离) )由此你得到了初始运动向量 {F*Math.cos(angle),F*Math.sin(angle)};

从这里开始,它只是平面运动学。路径通过等式可能看起来像这样:

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's path 
                                                  //relative to time is quardatic.

根据您将使用的类型,您可能需要在其中添加一些转换。所有常数都取决于您的游戏,但我发现它是 1 的倍数。使爆炸在视觉上更具吸引力,即随着时间计数器 t 的增加,对象的移动可能会使用 time_constant 0.5。

If it is going to be realistic(ish), like Angry Birds, then for each object that is blown apart by the bomb, it will follow a quadratic path.

I dont know andengine or box2d. But I have done simple 2d explosion and projectile modelling in a game.
I hope you can take something from the following:

You would want to find out the (x,y) coord distance of the object from the bomb. From this calculate the angle. (for example an object above the bomb as it explodes will have angle 90 or pi/2.

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

From here out it is just plane kinematics. The object should follow a quadratic path through the air. The equations may look something like:

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's path 
                                                  //relative to time is quardatic.

You will probably need to add some casts in there depending on what types you will use. All the constants depend on your game. time_constant may well be 1, but I found doing a multiple of 1 made the explosion more visually appealing. i.e. as your time counter t increments, the movement of the object may use time_constant 0.5. I used a lot of trial and error to see what constant values worked best.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文