void PatrolDirection(PatrolDir dir) { currentDirection = dir; if (currentDirection == PatrolDir.RIGHT) { character.SetMovement(Vector2.right); } if (currentDirection == PatrolDir.LEFT) { character.SetMovement(-Vector2.right); } if (currentDirection == PatrolDir.STOPPED) { character.SetMovement(Vector2.zero); } }
private void TickRoaming() { Rigidbody body = GetComponent <Rigidbody>(); Vector3 currDest = CurrPatrolDestination; Vector3 moveDir = (currDest - transform.position).normalized; body.MovePosition(transform.position + moveDir * Time.deltaTime * kSpeed); if ((transform.position - currDest).sqrMagnitude <= kNodeThreshold) { mCurrPatrolNode += (int)mPatrolOscillateDir; switch (mPatrolMode) { case PatrolMode.Linear: mCurrPatrolNode++; if (mCurrPatrolNode >= PatrolPoints.Length) { mCurrPatrolNode = 0; } break; case PatrolMode.Oscillate: if (mPatrolOscillateDir == PatrolDir.Forward && mCurrPatrolNode >= PatrolPoints.Length) { mPatrolOscillateDir = PatrolDir.Reverse; mCurrPatrolNode = Mathf.Max(PatrolPoints.Length - 2, 0); } else if (mPatrolOscillateDir == PatrolDir.Reverse && mCurrPatrolNode <= 0) { mPatrolOscillateDir = PatrolDir.Forward; mCurrPatrolNode = 0; } break; } } }
// Start is called before the first frame update void Start() { character = GetComponent <Char2D>(); startPos = transform.position; currentDirection = startDirection; }