Libgdx 近战攻击碰撞检测 [英] Libgdx Melee Attack Collision Detection

查看:31
本文介绍了Libgdx 近战攻击碰撞检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 3D 模型实例的 3D 场景;我想做碰撞检测.我目前正在关注本教程(http://blog.xoppa.com/using-the-libgdx-3d-physics-bullet-wrapper-part1/).不过,我想要的有点复杂.

I have a 3D scene with 3D model instances; and I want to do collision detection. I'm currently following this tutorial (http://blog.xoppa.com/using-the-libgdx-3d-physics-bullet-wrapper-part1/). However, what I want is a bit more complicated.

有一个角色(一个 Knight.g3db 模型,它是 Libgdx 基本 3d 模型类的示例代码的一部分),它可以用剑攻击.我还有另一个模型实例,我想用剑攻击".

There's a character (a knight.g3db model that's part of the sample code from Libgdx basic 3d model class), and it can attack with a sword. I also have another model instance that I want to "attack" with the sword.

检查两个物体的碰撞是否不是问题,因为这可以从 Bullet 库中轻松检测到.我想要的可能是以下内容,但我不确定如何实施:

Checking if the two objects for collision isn't the problem since that can easily be detected from the Bullet library. What I would like is possibly the following, but I'm not sure how to implement:

  • 将剑作为碰撞对象,或者
  • 执行检查是否只有骑士的盒子"的前部与其他物体发生碰撞,或者
  • 在骑士角色前面创建一个单独的不可见虚拟框,并在发生碰撞时将其用作基础.

是否有任何您知道的参考资料可以做到这一点(如果上述建议的解决方案甚至可能的话)?或者如果有更好的解决方案,请告诉我.

Are there any references that you know that can do this (if the above proposed solutions are even possible)? Or if there's a better solution, please let me know.

我要避免的是:当另一个物体在后面并且仍然被击中时,骑士进行攻击.

What I'm trying to avoid: knight attacking while the other object is behind and still getting hit.

提前致谢.

推荐答案

如果你只是想避免背后的敌人被击中,你可以检查你是否正对着他们.我会认为你有一个用于移动的方向向量,检查该向量的旋转与根据你的位置和敌人计算的向量的差异.

If you just want to avoid enemies in your back being hit you could check if you are facing them. I'll take it you have a direction Vector for movement, check the difference in rotation of that Vector vs the vector calculated based on your position and the enemy.

这样的事情(免责声明:我的脑子里,不确定这是否有效,只是给你一个想法):

Something like this (Disclaimer: out of my head, not sure if this work and just to give you an idea):

float yourAngle = direction.angle();
float enemyAngle = new Vector2(enemyPos.x - playerPos.X, enemyPos.y - playerPos.y).angle();

if (yourAngle - enemyAngle < 30 && yourAngle - enemyAngle > -30) //enemy within a 60 degree cone in front of you.

这可能不是理想的解决方案,但它确实是一种廉价的解决方案,而且效果可能很好.

This might not be the ideal solution but it sure is a cheap solution and it might work very well.

这篇关于Libgdx 近战攻击碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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