请告诉我做的角色动画与Box2D的最好方法是什么? [英] Whats the best way to do character animations with Box2D?

查看:171
本文介绍了请告诉我做的角色动画与Box2D的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个2D,水下,动作RPG游戏为Android使用的Box2D的物理引擎,主要用于碰撞检测,碰撞响应以及在游戏中的人物动作包括墙壁,岩石的环境中,和其他生物

I am developing a 2D, underwater, action-RPG for Android, using Box2D as the physics engine, mainly for collision detection, collision response and movement of in-game characters within an environment comprised of walls, rocks, and other creatures.

我曾尝试实施使用Box2D的角色动画两种不同的方法,并已发现的问题与两个。由于我是新来的Box2D和物理引擎,我想AP preciate如何这些事情应该最好做一个建议。

I have tried two different approaches for implementing character animations using Box2D, and have found issues with both. As I'm new to Box2D and physics engines, I would appreciate a recommendation on how these things should best be done.

动画我试图做的例子如下:

An example of an animation I am trying to do is as follows:

一个鱼想攻击其他鱼类,所以执行以下操作:结果
1)向目标移动的速度结果
2)取一咬出目标生物的结果
3)转身逃跑,回到那里的攻击开始结果
4)将回面对目标,准备另一次攻击

A fish wants to attack another fish, so does the following:
1) Move towards target at speed
2) Take a bite out of target creature
3) Turn and flee, back to where the attack began
4) Turn back to face the target, ready for another attack

我已经试过这两种方法是:

The two approaches I've tried are:

A)应用力到攻击者(使用的 body.applyForce()的),将其移动朝向目标,那么另一种力量将其重新移回,后碰撞结果
问题:的结果
*经常攻击命中目标和反弹并进入以极快的速度飞驰回来,反弹的墙壁,到处都是。速度是pretty随机的,取决于它影响了目标,目标的质量等,它打破了动画和看起来很可怕。结果
*这是很难搞清楚什么力量应该适用于攻击者时,在物理世界中模拟特定的动画,所以它看起来逼真

A) Apply a force to the attacker (using body.applyForce() ) to move it towards the target, then another force to move it back again, after the collision
Problems:
* Frequently the attacker hits the target and bounces off and goes hurtling back at great speed, and bounces off walls, everywhere. The speed is pretty random, depending on where it impacts the target, the mass of the target, etc. It breaks the animation and looks terrible.
* It's very hard to figure out what forces should be applied to the attacker and when, to simulate a particular animation in a physics world so it looks realistic

B)直接设置攻击者的位置(使用的 body.setTransform()的)攻击者移动到正确的位置,因为它向前移动的每一步,然后再移回。结果
问题:的结果
*直接设置位置允许忽略与墙壁和其他生物的碰撞攻击,所以被陷在墙上的常见结果
*如果玩家被攻击的,我更新的世界坐标系原点作为玩家的动作,以保持玩家中旬屏幕。这种运作良好,除了当我开始一个动画,因为我不想在屏幕上跟随动画做的,但只是现在的速度,这我不知道,因为我重写的Box2D力量的运动组件/速度当我设置的位置。这是可能做到这一点我敢肯定,但很难 - 也许我缺少明显的东西。

B) Directly set the position of the attacker (using body.setTransform() ) to move the attacker to the correct position, as it moves forwards each step, then moves back again.
Problems:
* Directly setting the position allows the attacker to ignore collisions with walls and other creatures, so getting stuck in a wall is common
* If the player is attacking, I update the world origin as the player moves, to keep the player mid-screen. This works well, except when I start an animation, as I don't want the screen to follow the animation, but only the movement component of the existing velocity, which I don't know, as I'm overriding the Box2D forces/velocities when I set the position. It's possible to do this I'm sure, but difficult - maybe I'm missing something obvious.

我应该监测的碰撞?重写碰撞响应?别的东西吗?

Should I be monitoring the collisions? Overriding the collision response?? Something else?

那么,你会如何建议我处理这个问题?

So, how would you recommend I approach this problem?

推荐答案

我只用来与先知工作,但先知是Box2D的一个pretty直接端口,所以我希望这个答案仍然是有帮助的。

I'm only used to work with Farseer, but Farseer is a pretty direct port from Box2D, so I hope this answer is still helpful.

下一步将力量和瞬移还可以设置一个机构的直线运动速度。这样,您就可以拥有对球员的鱼移动不施加力量。您应该从鱼体捕获碰撞事件和每个事件进行比较,如果鱼已击中玩家,然后在与播放器,使得它不反弹的碰撞事件中设置假/ NoCollision。现在设置鱼体忽略与玩家身体的任何碰撞,并使用一个固定接头鱼粘到播放器。现在,您可以发挥你咬动画。

Next to applying force and teleporting you can also set the linear movement speed of a body. This way you can have the fish move towards the player without applying force. You should capture the collision events from the fish body and compare in each event if the fish has hit the player, then set false/NoCollision in the collision event with the player so that it doesn't bounce of. Now set the fish body to ignore any collisions with the player body and use a fixed joint to stick the fish to the player. You can now play your bite animation.

咬动画后要脱离鱼。启动您逃离动画,取出关节和瞬移鱼玩家身体的边缘(以便它不与它碰撞)。在此之后重新启用鱼和玩家之间的身体碰撞和从玩家发送鱼离开(通过重新设置直线运动速度,或通过力一个不错的反弹效果。

After the bite animation you want to disengage the fish. Start your flee animation, remove the joint and teleport the fish to the edge of the player body (so that it's not colliding with it). After that re-enable collisions between the fish and the player body and send the fish away from the player (either by setting linear movement speed again, or for a nice bounce effect via force.

这篇关于请告诉我做的角色动画与Box2D的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆