Enemy sprite freezes on first waypoint

Hello,

I have a bug where Enemy just freezes on the first waypoint.
If I change Vector 2 to Vector 3 in my code, as I read on the forum, the enemy moves properly on Scene view, but vanishes from Game view. I checked all “Z” axises and they seem to be correct (Paths and Waypoints are on the same “Z” axis).

There are no errors in console. Unity: 2019.3.7f1

Any thoughts? I am not even sure what other details to share, as I am pretty sure my code is correct.

Wave Config:

 public List<Transform> GetWaypoints()
    {
        var waveWaypoints = new List<Transform>();
        foreach (Transform child in pathPrefab.transform)
        {
            waveWaypoints.Add(child);
        }
        return waveWaypoints; 
    }

Enemy Pathing:

[SerializeField] WaveConfig waveConfig;
    List<Transform> waypoints;
    [SerializeField] float moveSpeed = 2f;
    int waypointIndex = 0;

    void Start()
    {
        waypoints = waveConfig.GetWaypoints();
        transform.position = waypoints[waypointIndex].transform.position;
    }

Regards,
Pawel

1 Like

It sounds like there’s some Z fighting going on.

Try changing the Order Layer of the sprite, see if that works, if it doesn’t, take a video or some screenshots and share, it should be easier to detect the error with some visual information.

Hi PaFro,

If increasing the value of Order in Layer didn’t fix the issue, make sure that the z-position of the camera is set to -10. The waypoints must be at z = 0, or at least in front of the camera.

1 Like

Hello,

Thank you for your responses. Changing Camera “Z” from -2 to -10 helped.
I think it would be worth to mention that Vector2 used in this script does not work with current Unity version and you need to update code in EnemyPathing.cs to Vector3.

Kind regards,
Paweł

Vector2 works but you have to ensure that the z-position of the waypoints and the enemies is set to 0.

1 Like

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