Need help with AStar implementation in isometric tilemaps

MelonatorMelonator Posts: 2Member
edited January 13 in 2D

Im almost done in implementing pathfinding using A*, the problem is that anything beyond the yellow axis in the tilemap (negative y coordinates) does not register in the astar points. I checked why and I discovered that the _MapSize _(which I set to 32,32) only registers tiles from 0-32 both on x and y.

Method that registers all the tiles in the Astar node

    List<Vector2> pointPath = new List<Vector2>();
                foreach(var y in GD.Range((int)MapSize.y))
                {
                    foreach(var x in GD.Range((int)MapSize.x))
                    {
                        var point = new Vector2(x, y);
                        if (ExistsInArray(point, Obstacles)) continue;
                        int pointIndex = CalculatePointIndex(point);
                        pointPath.Add(point);
                        AstarNode.AddPoint(pointIndex, new Vector3(point.x, point.y, 0.0f));
                    }
                }
                return pointPath;

Method that calculates the ID
return (int)(point.x + MapSize.x * point.y);

This code is not mine, it's from GDQuest, I just translated it to C#. I tried moving the tilemap node, and it did not work. I tried moving the camera and it still did not work. I noticed that no matter where the camera is, the top left corner is always 0,0. Hence, I couldnt place tiles beyond Y = -1.


Tags :

Comments

  • MelonatorMelonator Posts: 2Member

    Alright so I was able to solve it myself.

    I created custom boundaries in the map that takes in the whole camera (including all the coordinates, even negative ones) and added an offset to the generateID function so negatives would be turned into positive numbers.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file