0
\$\begingroup\$

I'm trying to make AI for enemies in my game. I applied a pathfinding (A*) script to my enemy sprite, after which the sprite began to follow the player. But when the enemy approaches the player, the enemy gradually disappears. This only happens in the Game section but in the Stage section the enemy does not disappear. And when the enemy is to the left of the player, he disappears altogether. How can this be fixed?

enter image description here

enter image description here

Here are the player settings: enter image description here

Here are the enemy settings: enter image description here

Here are the AIPath settings: enter image description here

Here is the enemy script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;

public class EnemyGFX : MonoBehaviour
{
    public AIPath aiPath;

    void Update()
    {
        if (aiPath.desiredVelocity.x >= 0.01f)
        {
            transform.localScale = new Vector3(-1f, 1f, 1f);
        } else if (aiPath.desiredVelocity.x <= -0.01f)
        {
            transform.localScale = new Vector3(1f, 1f, 1f);
        }
    }
}
\$\endgroup\$
5
  • \$\begingroup\$ Hmm, doesn't seem a problem related to the pathfinding if you ask me. I recommend checking other things in your scene \$\endgroup\$ Commented Apr 28, 2022 at 6:21
  • 1
    \$\begingroup\$ Maybe you should raise the enemy's SortingLayer so that it always renders top of the background. \$\endgroup\$ Commented Apr 28, 2022 at 7:29
  • \$\begingroup\$ To find out if it is a problem of your pathfinder, just deactivate it in the script and move both your player and the enemy at the position in the editor that causes the problem. It looks rather like the player has a huge transparent background that is erasing the sprite of your enemy \$\endgroup\$ Commented Apr 28, 2022 at 7:30
  • \$\begingroup\$ Yes you are right. The problem is with the player. But I don't know how to remove this background. \$\endgroup\$ Commented Apr 28, 2022 at 14:25
  • \$\begingroup\$ Walk us through the steps required to reproduce a player object that exhibits this problem. \$\endgroup\$ Commented Apr 28, 2022 at 21:18

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.