X
X
xXx_Unity_xXx2021-12-08 20:52:46
C++ / C#
xXx_Unity_xXx, 2021-12-08 20:52:46

How to make the bots rise vertically. stairs behind the player in Unity 2D?

( 2d game, side view ) I have a script to get the player up the stairs (trigger when W is pressed) and a script to follow the player. When I climb the stairs to the 2nd floor, the opponents remain under the player.
How to make them go to the stairs and climb it to the 2nd floor and follow the player further?
Here is the script to follow the player:61b0f0a63a75e875793306.jpeg

private void Update()
    {   //вычисляем расстояние  между игроком и врагом
        float distToPlayer = Vector2.Distance(transform.position, player.position);
        if (distToPlayer < agroDistance)
        {
            StartHunting();
        }
        else
        {
            StopHunting();
        }
        if (health <= 0)//если у зомби кончилось здоровье то
        {
            Instantiate(blood, transform.position, Quaternion.identity); //кровь после смерти
            Destroy(gameObject);//то зомби уничтожается
        }
    }
    void StartHunting()//функция охоты СЛЕЖКА
    {
        if (player.position.x < transform.position.x) //идёт влево
        {
            physic.velocity = new Vector2(-speed, 0);
            transform.localScale = new Vector2(1, 1);
        }
        else  //идёт вправо
        {
            physic.velocity = new Vector2(speed, 0);
            transform.localScale = new Vector2(-1, 1);
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Blag Angymyn, 2021-12-09
@Fortfoxium

I don’t really rummage right for the code, I just started it myself, but the algorithm is in the spirit:
If the player is higher in coordinates, then
go to the ladder object and
change the coordinates to equal the player

spoiler
сожрать

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question