68

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 check, we fire rays to selected bone positions in Sam's animated skeleton, and tally up how much of him is visible. (We also evaluate lighting per bone, so they ...


67

Dungeons and Dragons 3.5 (pen-and-paper RPG) has a solution used for both movement and grid-based radius calculations: diagonal movement costs 1.5 what orthogonal costs. Since the diagonal of a unit square is approximately 1.414, 1.5 is pretty close. Because D&D 3.5 only supports integer movement, the way this is actually calculated is that orthogonal ...


66

You need to change the shape of the field of view. So that when you move in any direction, the same number of new squares become visible. Here is one possibility:


26

To have diagonal and orthogonal movement reveal approximately the same area, you need two things (each of which, alone, has already been suggested in another answer or comment): Approximately circular view range: On its own, this won't give exactly the same revealed area for both types of movement. For example, in the image above, orthogonal movement ...


23

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 plain white while everything else renders black - any pixels which are white in the result show a potential target. You can even use multiple colour channels to ...


11

Since you are using a grid and know which direction the user is proceeding there is nothing constraining you from adapting the prior answer and using a different fields of view depending on the direction. For example you could extended the field to include the corners when you travel in cardinal directions and shrink it down two squares on each end in your ...


8

As requested, one possible solution (with some flaws) is to use raycasting: Attaching a (C#) Script similar to this to the GameObject from which you want to check visibility would work: if(renderer.isVisible) //Check if Camera is turned towards the GameObject first { RaycastHit hit; // Calculate Ray direction Vector3 direction = Camera.main....


7

Do the LOS and AOI (Area Of Interest) filtering on the server. Yes, any data you send the client can be hacked. OR extra programs can be inserted as a proxy between client and server to sniff excess data, like the old EverQuest viewer that lets players not only see far-away monsters but even what loot they would drop (which is a bit mind-boggling why that ...


7

I have implemented the algorithm suggested by Jimmy. Video of the code in action here: https://youtu.be/lIlPfwlcbHo /* What this code does: Rasterizes a single Field Of View octant on a grid, similar to the way FOV / shadowcasting is implemented in some roguelikes. Clips to bitmap Steps on pixel centers Optional ...


7

How about, rather than having a fixed viewing range, have the player's visibility area depend upon what direction the player was facing, as well as perhaps the direction the player faced in the last few turns (a player who was moving north might be able to immediately take a step south, but might take a few turns to get maximum viewing distance in that ...


7

As long as your movement space isn't Euclidean and things can block an entire grid space, you'll have this problem. If you want people to not "play the grid" you're probably going to have to not use a grid.


6

The first thing I would suggest is to use a 2d implementation like the one in Teleglitch, like you said yourself, you found solutions, this is a lot simpler. Line of sight is a gameplay mechanic. If the game is top-down, the gameplay is essentially 2d and there is likely a limited benefit to using actual 3d line of sight. No, you are absolutely right. This ...


6

(I don't have enough reputation to comment) The answer here is that the distances are wrong. A is closer than B. To convince yourself, compare A and the reflection of B w.r.t. the player, so I don't think there is an issue here. Hex grids are tricky in a lot of ways.


5

Depending on your exact needs, another possible solution would be to do a test render where you set different objects to different colors and then check for that color in the test render. However this would only be useful in pretty obscure situations; in the majority of situations I would use raycasting. I'm just dropping in this different answer for ...


5

If you use an algorithm like Bresenham, where the two lines can be different, depending on their start- and end-position, you then have to either: Plot both lines and use the result of both plots for your LoS calculation. Plot only one line (for example always from Player to Enemy) and use this one LoS calculation for both entities.


4

Basically, you're going to be doing raycasting to figure out where exactly the vision gets blocked. The complexities come in with trying to make that clean and efficient and fit with how you're managing the actual scene. Other people have done a much better job explaining everything than I can, so I'm just going to reference them. Amit has a fantastic ...


4

The shape is irregular because of the obstacles. If you shoot a ray in every direction (360 cicle around unit), you determine if you hit an obstacle, and if yes, at what distance. If the ray does not encounter any obstacles before reaching the line of sight distance, then it stops, otherwise it stops at the point of encounter. This is by no means efficient ...


3

You won't get away on this one with an easy answer. The raycast method is completely flawed. Its the same as calling the object "one pixel" wide and checking if this pixel is visible or not. Unity uses a precalculated visibility matrix, composed with regular sectors of your world, and a quadratic ray cast test. Which has the same flaws but you don't need to ...


3

As an alternative to a more complex field of view (which as discussed above adds its own problems because of the constraints of a grid-based layout) you could try to emulate the effect of movement in a game that isn't based on a discreet grid. Where free movement is possible a diagonal move of one unit would be exactly that, not the ~1.41 units of movement ...


3

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 few random points belonging to the player model to check. This might even add a bit of realism to the experience: the AI will instantly detect the fully exposed ...


2

You could make the player move two spaces if they move up, down, left or right, and only one diagonally. It wouldn't completely even it out, but it would be much closer.


2

A system which never has any false-negatives is going to need to rely on some variant of graphics occlusion query. Ray casts and other physics-based measures will not work. You can use a GPU Occlusion Query for the easiest solution. Render your static geometry (just solid geometry, no need for colors or textures or other surface effects; you don't even ...


2

The trick is to cast rays from the source point to the edges of occupied squares. Then sort the rays by their angle. You then 'sweep' those angles and cull the pixels that are behind the intersection points. There are ways to optimize the algorithm by removing rays that have multiple intersections, as these rays will always be between rays that have only ...


2

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: s = (1/d) ((x00 - x10) y01 - (y00 - y10) x01) t = (1/d) -(-(x00 - x10) y11 + (y00 - y10) x11) (x00, y00) are the first segment's first point, (x01, y01) are the first segment's second point and similarly (x10, y10)...


2

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 cover that is not "a wall", i.e. a character standing near a car that simply occludes LoS but is not a proper cover) Most games do a gradual checking ...


1

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 necessary to add a collider to cover the radar building's pivot point, which was exposed in my setup. The code needed for line-of-sight detection is this: ...


1

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 use, which may have some useful inspirations for this problem. Their algorithm is approximate and conservative (it will err on the side of saying something is ...


1

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 using two different lighting solutions ... 1) The Visible view - what your player character can see now. Use normal lighting such as HSAmbient + Point + Cone ...


1

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 are (a) just now entering an obstacle, (b) already inside an obstacle, or (b) just now leaving an obstacle. You can intersect a ray with the relevant object to ...


1

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 fine in this case, and is fairly simple to implement. It subdivides a rectangular area of the game world into four equally sized rectangles, and continues to do ...


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