Pathfinding working but traveling on Y vector not Z

Hi, I have battled hard with this section of the course, really enjoyed it but tough going in places. Finally nearing the end and I have found an issue i cannot solve. My pathfinding script is working but my models follow it along the X axis (left to right) no problem but when they need to go ‘up’ the screen (Z Axis) they actually ride straight up in the air (Y Axis).

The problem must be that the path is simply send back the wrong axis but I cant find a solution.

Cheers

As usual, fresh pair of eyes found the mistake in the morning, I had indeed left a reference to y when it should have been a z (second part of code - GridManager).

   public Vector2Int GetCoordinatesFromPosition(Vector3 position)
    {
        Vector2Int coordinates = new Vector2Int();
        coordinates.x = Mathf.RoundToInt(position.x / unityGridSize);
        coordinates.y = Mathf.RoundToInt(position.z / unityGridSize);

        return coordinates;
    }

    public Vector3 GetPositionFromCoordinates(Vector2Int coordinates)
    {
        Vector3 position = new Vector3();
        position.x = coordinates.x * unityGridSize;
        position.y = coordinates.y * unityGridSize;
}
2 Likes

Does that mean you fixed the issue, @Moosegun? :slight_smile:


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms