Answer the question
In order to leave comments, you need to log in
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:
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
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question