public override void LogicUpdate() { if (target) { Vector2 distance = target.position - rb.position; Vector2 dir = new Vector2(Mathf.Sign(distance.x), Mathf.Sign(distance.y)); motion.SetSpeed(dir * maxSpeed); } }
public override void LogicUpdate() { if (Vector2.Distance(rb.position, destination) > 0.1f) { motion.SetSpeed(speed); } else { _switcher.SetState(_nextState); } }
// Update is called once per frame void Update() { if (target) { Vector2 distance = target.position - rb.position; if (!IsFollowing && zoneOfDetecting.Contains(distance)) { IsFollowing = true; Debug.Log("follow"); } IsInMinDistance = minDistance.Contains(distance); if (canMove) { if (IsFollowing && !IsInMinDistance) { Vector2 dir = new Vector2(Mathf.Sign(distance.x), Mathf.Sign(distance.y)); motion.SetSpeed(dir * maxSpeed); motion.Execute(); } //если нажали клавишу для перемещения вправо, а персонаж направлен влево if (distance.x > 0 && !isFacingRight) { //отражаем персонажа вправо Flip(); } //обратная ситуация. отражаем персонажа влево else if (distance.x < 0 && isFacingRight) { Flip(); } } if (IsFollowing && !zoneOfLosting.Contains(distance)) { IsFollowing = false; Debug.Log("not follow"); } } }