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]); }
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()); }
void DoFacing() { Vector3 facingVector = player.transform.position - this.transform.position; EntityFacing facing = Facing.DirectionToFacing(facingVector); animator.Play("ArcherWalk" + facing.ToString()); }
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); } }
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); }
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; }
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); } }
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; } } }
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); } }
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)); } }
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); } }
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; } }