简体   繁体   English

Libgdx实现射击(子弹和物体之间的碰撞)

[英]Libgdx implementing shooting (collision between bullet and objects)

I am new to 3D programming, just started yesterday. 我是3D编程的新手,昨天才开始。
I am just trying to create a simple game, where i move in 3D space, but collision detection works in 2D top down space, cause my character can't jump. 我只是尝试创建一个简单的游戏,在3D空间中移动,但是碰撞检测在2D自上而下的空间中起作用,导致角色无法跳跃。 So collision happens only on X and Z axis. 因此,碰撞仅发生在X和Z轴上。
But now i think about implementing shooting, where the bullet flies in the direction my camera is pointing (first person camera). 但是现在我考虑实施射击,子弹朝着我的相机指向的方向(第一人称相机)飞行。 But i have no idea how shooting is normaly implemented in 3D games? 但是我不知道在3D游戏中通常如何进行拍摄? Is a Bullet an object, which is drawn, like in many 2D games, and moved at high speed? Bullet是像许多2D游戏中一样绘制并高速移动的对象吗? Or is it just a line, which isn't even shown sometimes? 还是只是一条线,有时甚至没有显示? And how can i check for collision with that line without iterating throught all walls and mobs? 我如何在不遍历所有墙壁和生物的情况下检查与那条线的碰撞? I know you can find the areas throught which the bullet flies, but isn't this a big calculation when the line can go in every direction in 3D space? 我知道您可以找到子弹飞过的区域,但是当线可以在3D空间中的各个方向上走时,这不是一个很大的计算吗?

Depends if you want to show the bullet, then you can make a bullet model and make it move very fast. 取决于是否要显示项目符号,则可以创建项目符号模型并使它移动得非常快。

These are good options each one better than the previous 这些都是不错的选择,每一个都比以前更好

  • You can check for collisions iterating all the objects. 您可以检查所有对象的冲突。
  • You can have all the objects in nodes that have a reference to their neighbors and check collisions on them 您可以将所有对象包含在引用其邻居的节点中,并检查它们之间的冲突
  • Same as previous, but you take into account the direction vector of the bullet and only check the neighbors that are in front of it. 与之前的相同,但是您考虑了子弹的方向向量,只检查了子弹的前面的邻居。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM