68 votes

How to make AI detect a target behind a wall, who is only partially exposed?

This isn't common in all shooter games, but some do go to this level of detail. In Splinter Cell games, for instance, AI can detect Sam's individual body parts. When an AI is performing a detection ...
DMGregory's user avatar
  • 134k
23 votes

How to make AI detect a target behind a wall, who is only partially exposed?

If you really want to detect any exposed part of the player, the extreme approach is to simply render the scene from the gun's perspective using replacement shaders, such as the player rendering as ...
Dave's user avatar
  • 331
8 votes

More efficient way to implement Line of sight on a 2d grid with ray casting?

I have implemented the algorithm suggested by Jimmy. Video of the code in action here: https://youtu.be/lIlPfwlcbHo ...
Stoiko's user avatar
  • 99
3 votes

Line-of-sight algorithm for tile-based tactics

This is a partial answer. I can explain the cause of the problem you're seeing, but I don't have any proposal to fix it. Subsets of valid sightlights are not guaranteed to be valid sightlines This is, ...
Tim C's user avatar
  • 410
3 votes

How to make AI detect a target behind a wall, who is only partially exposed?

I assume your current way of detecting visibility is checking a clear line to the centre of the bounding box? If so, then one viable approach would be to keep doing this, but additionally choose a ...
IMil's user avatar
  • 139
3 votes
Accepted

Supercover line algorithm from corners instead of the square's center?

The solution was to use "A Fast Voxel Traversal Algorithm for Ray Tracing", as suggested by DMGregor, to trace a ray from/to "world" position instead of a grid cell's coordinate. I ...
Ainsley Harriott's user avatar
2 votes

How to implement D&D 4e's line of sight algorithm?

We can check if a square and a line segment intersects by dividing the square into 4 line segments, then using the following formula from here: ...
Bálint's user avatar
  • 14.9k
2 votes
Accepted

3D line segment AABB collision, with hit normal?

but I'm wanting to detect intersection with a 3D line segment (not an infinite ray) with a 3D AABB Most of these ray intersection algorithms return the hit distance. All you need to do is check that ...
Krupip's user avatar
  • 1,763
2 votes

How to make AI detect a target behind a wall, who is only partially exposed?

Building on previous answers, the most common solutions are to raycast multiple times, although I believe your approach of querying for enemies that are near walls can get buggy over time (if you add ...
andreferreirav2's user avatar
2 votes

Inconsistent movement / line-of-sight around obstacles on a hexagonal grid

The mistake in this post was treating any red line that crosses a hex as being equal. Those red lines are not all the same length in the Euclidean space of the player's screen (ignoring the grid). If ...
DMGregory's user avatar
  • 134k
1 vote
Accepted

Line-of-sight algorithm for tile-based tactics

As the answer by Tim C explained, it's not possible in a tile-based world to guarantee that a character who can see a tile can also see it from any point which counts as part of that line-of-sight. ...
Philipp's user avatar
  • 119k
1 vote
Accepted

Need help with fixing Optimized Raycasting / Line of Sight algorithm

...
Engineer's user avatar
  • 29.5k
1 vote

2D line of sight - hiding all tiles behind walls

The simplest implementation is for your Tile class to have two members: visible and opaque. ...
Casey's user avatar
  • 2,025
1 vote

Finding cells between two points (along line) to finding obstacles

I implemented the pseudocode from wikipedia for Bresenham's algorithm and got a result like this: ...
James L.'s user avatar
  • 111
1 vote

How to make a vision cone for the enemy in game maker?

I will be giving the answer assuming that your sprites were designed this way (with the front side up): The origin of sprites is middle center and bottom center, respectively. obj_Enemy - Create ...
Boneco Sinforoso's user avatar
1 vote

NavMesh - LoS and "Containing"

Firstly, ~300 triangles or ~200 border lines is peanuts to a modern computer. You're unlikely to see problematic inefficiencies with such a tiny amount of data to process each tick. To check if the ...
DMGregory's user avatar
  • 134k
1 vote
Accepted

Unity Hit Collider GameObject is Null when Collider is Child (Line-of-Sight Detection Problem)

This method tests positions against each other. If a game object does not have a collider at its pivot point, no collider will be found, causing a null exception. To fix the null errors, it was only ...
Denis G. Labrecque's user avatar
1 vote

Fastest visibility calculation towards all possible directions

Minecraft has to solve a similar problem for culling caves and other landscape features that are occluded from view. There's a detailed write-up here about the Advanced Cave Culling Algorithm they ...
DMGregory's user avatar
  • 134k
1 vote

How can I create a fog-of-war based on character line of sight mesh and a shader?

Well, it appears to me that you already have part of the solution. You should accumulate the raycast mesh over time, that gives you a 'memory' of what you've seen. Then you need to render your scene ...
Gavin Williams's user avatar
1 vote

Best way to get the maximum moveable Area

Place the origin z at what you call the "unit." In that coordinate system, list all the vertices of your objects. Sort them angularly about z. Walk through the sorted list, and determine whether you ...
Joseph O'Rourke's user avatar
1 vote

Simultaneous line of sight for hundreds of individual agents on a grid?

If you haven't already, look into using optimisation algorithms and data structures such as quadtrees, spatial hashing, binary space partitioning, and so on. A quadtree in particular would do just ...
Domagoj's user avatar
  • 216
1 vote

How to find grid cells not seen by an object

You haven't specified what sort of output you're looking for. If there really could be millions of grid cells unseen, finding them all will necessarily require processing millions of grid cells. So ...
congusbongus's user avatar
  • 14.8k

Only top scored, non community-wiki answers of a minimum length are eligible