Skip to main content

Bresenham line for LOS.

I spent some time today optimizing and modularizing the script I've been using to prepare it for having more than one player character. I also moved the mini map to an overlay scene.
Finally I started doing some tests on LOS.

Originally I had thought of using raycasting LOS, as this is a 3d game, I may as well take advantage of the power of a modern PC right? But after some consideration I'll be using the Bresenham line drawing algorithm to check for line of sight in the game and I've also been thinking of how I can use it in path finding. It is rather a nice algorithm and the worst part about it I can see is that it sometimes draws rather ugly lines when they veer near to the vertical or horizontal.

Here's an example of the LOS in game:


It's just an illustration of course so in the final game there won't be any indicators, the slime will just not be visible to the player. the beauty of using this implementation is that I don't have to do any ray-casting. I just check the walk dictionary (which includes both walkable squares and flyable squares) for each enemy in range and if any point on the line is not in the dictionary the chosen object is not visible.

I've read a little about using the algorithm for pathfinding too, but I'm not sure I'll be able to get it to work with non diagonal movement (which is a corner stone of my game). Lets wait and see.

 EDIT: After some experiments I've decided that diagonal movement is perhaps OK after all. I'll be doing some fixes to make sure that players and enemies don't try to cut corners through the scenery, but most of that should be possible to handle by modifying the walk meshes anyway. The Line algorithm works really well with pathfinding creating fairly natural looking diagonal paths and cutting down on processing time a lot compared to A*. One thing I specifically want to avoid is players or enemies squeezing between a wall corner and another player/NPC or moving diagonally in to a square which can't be reached by regular NSEW movement.

Comments

Popular posts from this blog

Automating Level imports from Blender to Godot

  Recently I've been making some levels in Blender an importing them into Godot. There are only about 7 or 8 shaders for each level, not counting dynamic objects which will be added later. But to improve rendering performance, it can be a good idea to split the meshes up into sections. At that point you might be faced with a list like this: Or it might be even more chaotic, if you didn't use simple names for the objects in your level. So it can take a long time to sort out all the meshes, make them unique and add textures and so on. Blender imports with simple Blender textures, or with placeholder materials. This is sometimes OK, but if your Godot shaders are very different to those used by Blender, it means applying new materials to every mesh object in the level when you import the scene. I found that during the design process, I was importing and readying a level several times before I was happy with the final layout. So at first I was wasting a lot of time. In Blender, I us

Upstairs / Downstairs.

I've decided to make my prefabs multilevel. Later this should allow me to add pit traps and other great stuff. It also makes it easier to line up stairs so that you can exit them on the same co-ordinates where you entered them. The prefab editor is pretty much finished, it just needs some code for loading up prefabs from a saved dictionary, so that they can be checked or edited. The entries will need to be forwards compatible, so I'll be loading each tile and then translating the indexes to a new array, that way if I add extra indexes or extra info (like traps or puzzles) I'll be able to update existing prefabs to work with the new standard. Click for a video.

Make your game models POP with fake rim lighting.

I was watching one of my son's cartoons today and I noticed they models were using serious amounts of simulated rim lighting . Even though it wasn't a dark scene where you'd usually see such an effect, the result was actually quite effective. The white edge highlighting and ambient occluded creases give a kind of high contrast that is similar to, but different from traditional comic book ink work. I'll be honest, I don't know if there's a specific term for this effect in 3d design, since my major at university was in traditional art. I learned it as part of photography. You can find plenty of tutorials on "what is rim lighting" for photography. It basically means putting your main sources of light behind your subject so that they are lit around the edges. It can produce very arresting photographs, either with an obvious effect when used on a dark subject ... ..,or as part of a fully lit scene to add some subtle highlights. See ho