视线 2d
谁能解释一下二维的视线是如何工作的?这对我的二维实验非常有帮助。正在进行的实验是一个简单的二维模拟。玩家在世界中从一个地方移动到另一个地方,我的世界就是这样的。我成功地将角色从一个点移动到另一个点(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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白你的段落,但要回答你的问题(假设我们想知道在自上而下的游戏中敌人是否可以看到玩家)
检查玩家位于敌人的视野中。我们通过计算(的绝对值)来做到这一点敌人视线矢量与 跨越敌人和玩家之间的向量。如果为 0°,则敌人面向玩家。如果是 180°,则敌人的视线远离玩家。检查它是否<比如说,30°,给敌人 60° 的视野(或者 <45°,给敌人 90° 的视野)。
检查敌人和玩家之间没有任何东西。这归结为检查墙壁(或其他任何东西)与跨越敌人和玩家的线段之间的碰撞。
请注意,如果有很多墙,检查所有墙的碰撞可能会非常昂贵。将搜索范围缩小到仅几个对象称为修剪,这超出了本答案的范围(请参阅此处了解更多信息)
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)
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°).
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)
视线可能是一种非常昂贵的算法。目标是确定两点(可以说是眼睛和物体)之间是否存在物体。
为此,您必须获取途中所有潜在物体的列表(四叉树可能对以下情况有用 ):这个,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