コード例 #1
0
ファイル: ChaseState.cs プロジェクト: cadenkesey/lilith
    public override void UpdateState()
    {
        if (EnteredState)
        {
            _timeSinceLastUpdate += Time.deltaTime;

            if (_cornerIndex <= _pathCorners.Length - 1)
            {
                // Get the next movement vector, and if true then the corner will be reached
                if (FairyOperations.GetNextPosition(_pathCorners[_cornerIndex], FairyCharacter.GroundCheck.transform.position, FairyCharacter.MovementSpeed, out Vector3 nextMovement))
                {
                    // Prepare to move to next corner on next update
                    if (_cornerIndex <= _pathCorners.Length - 1)
                    {
                        _cornerIndex += 1;
                    }
                }

                // Check that the enemy is not moving too close to the player
                if (FairyOperations.CheckNextPosition(nextMovement, FairyCharacter.transform.position, FairyCharacter.Player.transform.position, 2.0f))
                {
                    // Get a new point to move to
                    if (FairyOperations.RandomPoint(FairyCharacter.Player.transform.position, 10.0f, out Vector3 point))
                    {
                        SetDestination(point);
                    }
                }
                // Move towards the new position and look towards it too
                else
                {
                    FairyCharacter.transform.position += nextMovement;

                    Vector3 nextLook = new Vector3(nextMovement.x, 0, nextMovement.z);
                    if (!nextLook.Equals(new Vector3(0, 0, 0)))
                    {
                        FairyCharacter.transform.rotation = Quaternion.LookRotation(nextLook);
                    }
                }
            }

            // Check if the enemy should update its path
            if ((_cornerIndex >= _pathCorners.Length) || (_timeSinceLastUpdate >= _timeBetweenDestinationUpdates))
            {
                SetDestination(FairyCharacter.Player.transform.position);
            }
        }
    }