视线 2d

发布于 2024-10-28 10:15:43 字数 527 浏览 0 评论 0原文

谁能解释一下二维的视线是如何工作的?这对我的二维实验非常有帮助。正在进行的实验是一个简单的二维模拟。玩家在世界中从一个地方移动到另一个地方,我的世界就是这样的。我成功地将角色从一个点移动到另一个点(A 到 G),我的目标是 - 当角色经过每个点时,它必须在该区域执行一些搜索,然后再离开到下一个点。为了实现这一目标,我觉得方法点是更好的解决方案,任何人都可以帮助我。谢谢!

编辑 : 一旦玩家进入房间/检查点,我就会带用户前往下一个场景 像这样< /a>
在此处输入图像描述

拾音器放置在画布上的某个位置,我的玩家必须将它们全部收集起来并离开该区域- 返回地图场景。

Can anyone explain how the line of sight works in 2d? Which will be really help full for my 2d experiments. The experiment am working is a simple 2d simulation. Player move in the world from one place to other , my world exactly looks like this. I did the character movement successfully from one way point to other (A to G) , my goal is - when the character passes each point it has to perform some search in that area before it leaves to next point. To achieve I felt way point is better solution , can anyone help me on this.Thanks!

Edit :
As soon as the player enters a room/checkpoint I will take user to next scene like this
enter image description here

where the pickups are place some where on the canvas and my player have to collect them all and leave the area - Back to Map scene.

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

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

发布评论

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

评论(2

请止步禁区 2024-11-04 10:15:43

我不明白你的段落,但要回答你的问题(假设我们想知道在自上而下的游戏中敌人是否可以看到玩家)

  1. 检查玩家位于敌人的视野中。我们通过计算(的绝对值)来做到这一点敌人视线矢量与 跨越敌人和玩家之间的向量。如果为 0°,则敌人面向玩家。如果是 180°,则敌人的视线远离玩家。检查它是否<比如说,30°,给敌人 60° 的视野(或者 <45°,给敌人 90° 的视野)。

  2. 检查敌人和玩家之间没有任何东西。这归结为检查墙壁(或其他任何东西)与跨越敌人和玩家的线段之间的碰撞

    请注意,如果有很多墙,检查所有墙的碰撞可能会非常昂贵。将搜索范围缩小到仅几个对象称为修剪,这超出了本答案的范围(请参阅此处了解更多信息)

I didn't understand your paragraph, but to answer your question (assuming we want to know if an enemy can see the player, in a top-down game)

  1. Check that the player is in the enemy's cone of vision. We do this by computing the (absolute value of the) angle between the enemy's sight-vector and the vector spanning between the enemy and the player. If it is 0°, the enemy is facing the player. If it is 180°, the enemy is looking away from the player. Check that it is < 30°, say, to give the enemy a cone-of-vision of 60° (or <45° to give the enemy a cone-of-vision of 90°).

  2. Check that there is nothing between the enemy and the player. This boils down to checking for a collision between the walls (or anything else) and the line segment spanning the enemy and the player.

    Note that if there are many walls, checking for collision with all of them can be very expensive. Narrowing the search down to only a few objects is called pruning, and outside the scope of this answer (see here for more information)

甜`诱少女 2024-11-04 10:15:43

视线可能是一种非常昂贵的算法。目标是确定两点(可以说是眼睛和物体)之间是否存在物体。

为此,您必须获取途中所有潜在物体的列表(四叉树可能对以下情况有用 ):这个,http://en.wikipedia.org/wiki/Quadtree)并测试它们中的每一个看看它们是否与眼睛和物体之间的线相交。

您可能想研究探路:http://en.wikipedia.org/wiki/Pathfinding

Line of sight can be a very expensive algorithm. The objective is to determine whether or not an object exists between two points (the eye and the object, you could say.)

To do this, you have to get a list of all potential objects in the way (a QuadTree might be useful for this, http://en.wikipedia.org/wiki/Quadtree) and test each of them to see if they intersect the line between the eye and the object.

You may want to research Pathfinding: http://en.wikipedia.org/wiki/Pathfinding

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