Tag Info

Ways to draw tracks on 4-connected grid

This is Matt, the creator of Trainyard. @DMGregory summoned me here! :) It sounds like you're working through the same issues I had to deal with. It's a tricky problem where there isn't necessarily a ...
• 371
Accepted

Casting Civilization V based Hex Grid on Unity Terrain and Select Certain Areas of Grid

There's a useful isomorphism we can exploit between hex grids and square grids: with a simple shear transformation, we can transform one into the other. We'll use this in two ways: We'll use the ...
• 134k

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 ...
• 99

Calculate the distance/number of moves one square is from another

If you don't need to navigate around obstacles along the way, you can do this with a simple formula. Just like in continuous space we can use the Euclidean distance metric: d_{\text{Euclidean}} = \...
• 134k
Accepted

How can I procedurally find a wall that separates two or more points on a grid-based map?

I will present a general concept and three solutions using that concept. Concept is an Influence map: For each location in the map, you are going to store a number that represent the distance to each ...
• 26.7k

Elegantly transition from 4-grid to 6-grid and back

This is most intuitive way that I can think of.
• 1,923

How does HPA*(Hierarchical Pathfinding A*) really work?

One of the creators of HAA* (a generalization of HPA*) wrote a very accessible article explaining how it works on aigamedev.com. Unfortunately that site seems to be dead, but fortunately archive.org ...
Accepted

Finding all hexagonal grid coordinates inside cover arc

I prefer to do hex-cell coordinate math in what Amit calls cubical coordinates on your linked page. For the rest of this answer, (X, Y, Z) will refer to cubical coordinates. Basically, for any of ...
• 9,019
Accepted

What is the "Unity" way to approach tech design for a 2D game like this?

How do you approach Canvases in Unity? It's possible to use more than one screen-space canvas in Unity, but it's uncommon. There is usually no reason to do that, unless you want different UI elements ...
• 119k

Ways to draw tracks on 4-connected grid

I think you can solve the two pain points you indicated with a few heuristics. One is a little hysteresis: once the player is drawing in a particular row/column, keep their drawing cursor locked in ...
• 134k
Accepted

Find a encircliement in Hexagonal grid (optimization issue)

1. Optimize Needlessly Slow Operations Your basic approach should work well on small to medium maps, it's just that the way you've chosen to implement it is unnecessarily slow: You search the same ...
• 134k
Accepted

Representation of trains on a simplified rail grid

On tracking Your current simulation behaves pretty well, I would say. Because a rail wagon that is halfway a sharp bend, will indeed exhibit the behaviour that the wagon's center is no longer above ...
• 3,729

place sprites in grid pattern within an area

first time here, have some time to kill so this is what I did. I'm assuming this is in a gui/2d game. This is what i did to get it to work. create a canvas and add 4 UI images. These act as the 4 ...
• 41
Accepted

Finding a path with minimal number of turns on a grid?

First fix your A* implementation so that it will find the shortest path. Adjust the cost of the turn instead of the heuristic. This means that when you generate the neighbours the one going straight ...
• 7,256
Accepted

Find a path centered on the edge between traversable tiles

Your problem lies in generating the graph, before any actual pathfinding takes place. It looks like you want the intersections of tiles to be considered the nodes of your graph, and only want ...

What is the "Unity" way to approach tech design for a 2D game like this?

You would usually use the canvas for UI elements. You can anchor your elements relative to positions and it should take care of your scaling for different dimensions if done correctly. A gameobject ...
• 4,291

How to handle two player-programmed robots attempting to enter the same discrete grid cell in one game tick

Some ways I've seen this solved: Treat a collision as a failure state Zachtronics games like SpaceChem and Opus Magnum commonly go this route. The player is challenged to create a program that does ...
• 134k

How do I move a unit one grid-square-width per button press in Unity3D?

I think the best way to approach this would be to create a grid system where each square is 64x64 pixels, and then have your button press increment the square number. So the frog technically moves 64 ...
• 504
Accepted

Calculate position on Isometric grid

Looks like you want: ...
• 134k
Accepted

Diagonal symmetry across a filtered array?

You are writing to the same array you are reading from - that's what causes diagonal symmetry. Problem is you can't sample correctly if you have already begun to change the array you are sampling from!...
• 29.5k
Accepted

Messy results from simple cellular automata algorithm?

You require more effective smoothing methods. Google "cave generation" and you will find many. Also if you haven't already begun, some research on cellular automata will be beneficial. This issue ...
• 29.5k
Accepted

Creating random path in grid

Edit: I just noticed you don't have a fixed endpoint to steer towards. In this case, we can solve this with recursive backtracking: ...
• 134k
Accepted

How should I store world data in a 2D grid sandbox game?

But here is the problem, since not every tile's size is 1x1, some may take 2x3 block size. and if i just put in Array this object's pointer, there is 6 same pointer will store in single array. Don't ...
• 119k
Accepted

How to decorate the floor with a grid?

One way to do a square pattern in glsl is with mod: ...
• 26.7k

How to handle grid snapping when the object is greater than the grid cell width and height?

The problem is, that you seem to take the center of the shape as pivot. What you want is to select a pivot, that places the shape inside the grid, so that it overlaps as few cells as possible. How to ...
• 397
Accepted

Draw animating grid with terrain deformation and variable colors

When this question was just about drawing a plain grid of lines, I said... I'd be tempted to draw this with a shader on a single quad, using the world coordinates of the vertices to snap the lines to ...
• 134k

Find a path centered on the edge between traversable tiles

If I understand correctly, you want the algorithm to return a path that touches the center of each grid (the red dots, in your last image) rather than one that goes along the grid lines (the blue line,...
• 183
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 ...
Accepted

Holding "Shift" to lock mouse movements to a straight line?

Cache relevant x or y value after shift key is detected PseudoCode: ...
• 1,690
Accepted

How do I place objects so they snap to my TileMap in Godot?

Godot snaps to the grid guidelines and not the cells between them. So you won't snap to the middle of the square that you're dragging to. That's because you're snapping the position of the object (...
• 798

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