private void Update() { if (timer > 0) { timer -= Time.deltaTime; if (Mathf.Approximately(transform.position.x, player.transform.position.x)) { follow.HardStop(); } else { follow.MoveTowards(-new Vector2(transform.position.x, 0) + new Vector2(player.transform.position.x, 0)); } } else if (!shot) { shot = true; follow.HardStop(); anim.SetBool("Laser", true); lr.enabled = true; lr.widthMultiplier = 1f; lr.SetPosition(0, shootingPoint.position); lr.SetPosition(1, new Vector2(shootingPoint.position.x, -100)); } else if (check) { CheckCollisions(); } }
private void Update() { Vector3 dir = GameManager.instance.player.transform.position - transform.position; if (dir.magnitude > minDistance) { follow.MoveTowards(dir); } }
public override void Sight(RaycastHit2D sight) { base.Sight(sight); if (state == EnemyState.Idle && playerDetected && Vector2.Distance(player.transform.position, transform.position) < minDistance) { anim.SetTrigger("Chase"); state = EnemyState.Chasing; playerPos = GameManager.instance.player.transform.position; follow.MoveTowards((playerPos - transform.position).normalized); } }
/// <summary> /// Se mueve en una dirección aleatoria y actualiza el cooldown /// </summary> void Update() { if (changeDirectionCooldown <= 0) { follow.MoveTowards(CalculateDirection()); changeDirectionCooldown = changeDirectionEvery; } else { changeDirectionCooldown -= Time.deltaTime; } }
/// <summary> /// Dependiendo del estado, se mueve hacia el jugador o aleatoriamente /// </summary> private void Update() { switch (state) { case EnemyState.Chasing: moveRandom.enabled = false; followDirection.MoveTowards((player.transform.position - transform.position).normalized); break; case EnemyState.Idle: moveRandom.enabled = true; break; } }
public void Move() { Vector3 dir = (player.transform.position - transform.position).normalized; follow.MoveTowards(dir); if (dir.x > 0) { GetComponent <SpriteRenderer>().flipX = true; } else { GetComponent <SpriteRenderer>().flipX = false; } }
/// <summary> /// Dependiendo del estado en el que esté, acualiza su comportamiento /// </summary> private void Update() { switch (state) { case EnemyState.Fleeing: followDirection.MoveTowards((transform.position - player.transform.position).normalized); break; case EnemyState.Shooting: shooting.Cooldown(); shooting.Shoot(); break; } anim.SetFloat("Velocity", rb.velocity.magnitude); }
void Update() { if (Amigo != null) { if (Vector2.Distance(FollowPoint.position, transform.position) > 0.1f) { follow.MoveTowards(FollowPoint.position - transform.position); } else { follow.HardStop(); } } else { dronAss.enabled = true; this.enabled = false; } }
/// <summary> /// Si está en fleeing, se mueve contrario al jugador, si no, se mueve hacia él /// Actualiza el tiempo de melee /// Dispara /// </summary> private void Update() { if (!stunned) { switch (state) { case EnemyState.Fleeing: moveDir = (transform.position - player.transform.position).normalized; break; case EnemyState.Chasing: moveDir = (player.transform.position - transform.position).normalized; break; case EnemyState.Idle: follow.Stop(); break; } //Se suma avoidDir para hacer un movimiento compuesto moveDir += avoidDir; if (moveDir.magnitude > 0) { follow.MoveTowards(moveDir); } else { follow.Stop(); } moveDir = Vector2.zero; avoidDir = Vector2.zero; Cooldown(ref meleeTimer); shooting.Cooldown(); shooting.Shoot(); } else { follow.Stop(); } }
private void Update() { follow.MoveTowards(player.position - transform.position); }