Enemies are floating below ground

my enemies are floating below the ground’s level and nodes aren’t getting blocked. Also some enemies do follow the updated path and some follow the initial path.

My code for GridManager’s GetPositionFromCoordinates and GetCoordinatesFromPosition methods are as follows:

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 = Mathf.RoundToInt(coordinates.x * unityGridSize);
        position.z = Mathf.RoundToInt(coordinates.y * unityGridSize);
        
        return position;
    }

I though at first maybe my code was wrong as i saw a previous similar post, still couldn’t figure out. Please Help me
!! (I am using Unity 2022 )

Make sure all your objects are on the correct positions. Your EnemyPool is sitting at -21 on the y-axis. It’s also clear from the screenshot that your terrain is way above y=0, probably y=21 which is why the EnemyPool is at -21 (to compensate). The enemies are spawning with a y position of 0, and that is clearly not on the surface of the terrain

Did as you said, the enemies are visible now and all objects are at same level. Now, the remaining problem is only that enemies are not following updated path (some are following, some are not), also they are passing through the towers (they still follow their original path).

I think there is some problem in my enemy mover script
Or are the script execution works differently in unity 2022, i’m just blindly using new version of unity

1 Like

First thing I can see (from what you shared - not necessarily going to fix the problem) is your GetPositionFromCoordinates. Don’t do the Mathf.RoundToInt bits

public Vector3 GetPositionFromCoordinates(Vector2Int coordinates)
{
    Vector3 position = new Vector3();
    position.x = coordinates.x * unityGridSize;
    position.z = coordinates.y * unityGridSize;
    
    return position;
}
1 Like

Thank you very much
I saw that Garry too ran into the same problem at the last, I didn’t watch the video till last.
Sorry, My bad ! :frowning:

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

Privacy & Terms