コード例 #1
0
ファイル: EntityFacing.cs プロジェクト: nsparisi/n3-games
    public static EntityFacing RandomFacingThatIsntThisOne(EntityFacing thisOne)
    {
        int rand = Random.Range(0, 3);

        EntityFacing[] choiceArray = new EntityFacing[3];
        int            index       = 0;

        if (thisOne != EntityFacing.Up)
        {
            choiceArray[index++] = EntityFacing.Up;
        }

        if (thisOne != EntityFacing.Down)
        {
            choiceArray[index++] = EntityFacing.Down;
        }

        if (thisOne != EntityFacing.Left)
        {
            choiceArray[index++] = EntityFacing.Left;
        }

        if (thisOne != EntityFacing.Right)
        {
            choiceArray[index++] = EntityFacing.Right;
        }

        return(choiceArray[rand]);
    }
コード例 #2
0
    void DoFacing()
    {
        Vector3 facingVector = player.transform.position - this.transform.position;

        if (Mathf.Abs(facingVector.x) > Mathf.Abs(facingVector.y))
        {
            if (facingVector.x > 0)
            {
                facing = EntityFacing.Right;
            }
            else
            {
                facing = EntityFacing.Left;
            }
        }
        else
        {
            if (facingVector.y > 0)
            {
                facing = EntityFacing.Up;
            }
            else
            {
                facing = EntityFacing.Down;
            }
        }

        animator.Play("skeletonwalk" + facing.ToString().ToLower());
    }
コード例 #3
0
    void DoFacing()
    {
        Vector3      facingVector = player.transform.position - this.transform.position;
        EntityFacing facing       = Facing.DirectionToFacing(facingVector);

        animator.Play("ArcherWalk" + facing.ToString());
    }
コード例 #4
0
    private void PursuePlayer()
    {
//		if (modeTime > pursuitTime)
//		{
//      }

        if (modeTime > pursuitTime)
        {
            Mode = AIMode.Aim;
            //lock in facing
            facing = Facing.DirectionToFacing(Player.Instance.transform.position - this.transform.position);
        }
        else
        {
            destination = FindClosestAlignedDistance(this.transform.position, Player.Instance.transform.position, preferredFireDistance);
            Vector3 movement = destination - this.transform.position;
            float   timedPositioningSpeed = moveSpeed * Time.fixedDeltaTime;
            if (movement.magnitude < timedPositioningSpeed)
            {
                Mode = AIMode.Aim;
                //lock in facing
                facing = Facing.DirectionToFacing(Player.Instance.transform.position - this.transform.position);
            }
            else
            {
                movement = movement.normalized * timedPositioningSpeed;
            }
            base.MoveWithSliding(movement);
        }
    }
コード例 #5
0
 private void StartMove()
 {
     Mode = AIMode.Move;
     //choose direction
     facing     = Facing.RandomFacingThatIsntThisOne(facing);
     trajectory = Facing.FacingToUnitVector3(facing);
     //choose length of travel
     chosenTravelTime = Random.Range(minTravelTime, maxTravelTime);
 }
コード例 #6
0
    IEnumerator FellInHoleRoutine()
    {
        animator.Play(fallMotion.name);
        fellInHole = true;
        yield return(new WaitForSeconds(fallMotion.length));

        // reset and take damage
        this.transform.position = lastSafePosition;
        TakeDamage(holeDamage);
        hurtTimer = 0;
        facing    = EntityFacing.Down;

        yield return(new WaitForFixedUpdate());

        fellInHole = false;
    }
コード例 #7
0
    private void Move()
    {
        if (modeTime > chosenTravelTime)
        {
            StartFiring();
        }
        Vector3 positionBefore = transform.position;

        base.MoveWithSliding(trajectory * Time.fixedDeltaTime * moveSpeed);
        Vector3 positionAfter = transform.position;

        if (positionBefore == positionAfter)
        {
            facing     = Facing.OppositeFacing(facing);
            trajectory = Facing.FacingToUnitVector3(facing);
        }
    }
コード例 #8
0
 private void Firing()
 {
     if (modeTime > fireWait)
     {
         if (shotCount > maxShots)
         {
             shotCount = 0;
             StartMove();
         }
         else
         {
             //shoot and turn clockwise
             shotCount++;
             FireProjectile();
             facing   = Facing.RotateClockwise(facing);
             modeTime = 0f;
         }
     }
 }
コード例 #9
0
ファイル: EntityFacing.cs プロジェクト: nsparisi/n3-games
    public static EntityFacing RotateClockwise(EntityFacing facing)
    {
        switch (facing)
        {
        case EntityFacing.Up:
            return(EntityFacing.Right);

        case EntityFacing.Down:
            return(EntityFacing.Left);

        case EntityFacing.Left:
            return(EntityFacing.Up);

        case EntityFacing.Right:
            return(EntityFacing.Down);

        default:
            return(EntityFacing.Up);
        }
    }
コード例 #10
0
ファイル: EntityFacing.cs プロジェクト: nsparisi/n3-games
    public static Vector3 FacingToUnitVector3(EntityFacing facing)
    {
        switch (facing)
        {
        case EntityFacing.Up:
            return(new Vector3(0, 1));

        case EntityFacing.Down:
            return(new Vector3(0, -1));

        case EntityFacing.Left:
            return(new Vector3(-1, 0));

        case EntityFacing.Right:
            return(new Vector3(1, 0));

        default:
            return(new Vector3(0, 0));
        }
    }
コード例 #11
0
ファイル: EntityFacing.cs プロジェクト: nsparisi/n3-games
    public static EntityFacing OppositeFacing(EntityFacing facing)
    {
        switch (facing)
        {
        case EntityFacing.Up:
            return(EntityFacing.Down);

        case EntityFacing.Down:
            return(EntityFacing.Up);

        case EntityFacing.Left:
            return(EntityFacing.Right);

        case EntityFacing.Right:
            return(EntityFacing.Left);

        default:
            return(EntityFacing.Up);
        }
    }
コード例 #12
0
    void HandleFacing()
    {
        // Edge case
        if (inputMovement.x < 0 &&
            inputMovement.y > 0 &&
            facing == EntityFacing.Right)
        {
            facing = EntityFacing.Up;
            return;
        }

        // Don't change if moving diagonal
        if (inputMovement.x != 0 && inputMovement.y != 0)
        {
            return;
        }

        // Basic facings
        if (inputMovement.x > 0)
        {
            facing = EntityFacing.Right;
        }

        else if (inputMovement.x < 0)
        {
            facing = EntityFacing.Left;
        }

        else if (inputMovement.y > 0)
        {
            facing = EntityFacing.Up;
        }

        else if (inputMovement.y < 0)
        {
            facing = EntityFacing.Down;
        }
    }