public void moveToTarget(Transform target, MoveCallback callback) { currentState = MOVEMENT_STATE.TARGET; this.target = target; moveCallback = callback; doFacing(this.target.position); }
public void endMovement() { currentState = MOVEMENT_STATE.IDLE; if( !isServer && !isLocalPlayer ) return; if(moveCallback != null) { moveCallback(); } }
private void Ai_Reset( ) { Player = null; FollowingPlayer = null; Breadcrumb = null; FollowingAi = null; Waypoint = null; wanderTimer = 0; moveState = MOVEMENT_STATE.IsIdle; attackState = ATTACK_STATE.CanNotAttack; }
public void moveToLocation(Vector3 targetLocation) { currentState = MOVEMENT_STATE.LOCATION; this.targetLocation = targetLocation; this.target = null; doFacing(this.targetLocation); //float rot_z = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; //transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90); //facing = transform.TransformDirection (-Vector3.forward); // Debug.Log(facing); }
// Use this for initialization void Start() { drone = GameObject.FindGameObjectWithTag("Drone"); mainPlayer = GameObject.FindGameObjectWithTag("Player").GetComponent<ThirdPersonCharacter>(); audioSource = GetComponent<AudioSource>(); movementState = MOVEMENT_STATE.MOVING; cameraView = CAMERA_VIEW.PLAYER; health = maxHealth; bloodOverlay = imageOverlayObject.GetComponent<Image>(); SetHealth(100); }
private void setMovementState(MOVEMENT_STATE newState) { if (previousMovState == newState) { return; } logMoveState(newState); switch (newState) { case MOVEMENT_STATE.STOPPED: { animateStopping(); break; } case MOVEMENT_STATE.MOVING: { if (previousMovState == MOVEMENT_STATE.STOPPED) { animateStartingToMove(); } else { this.anim.CrossFade("Walk"); } break; } case MOVEMENT_STATE.JUMPINGHIGH: { if (previousMovState == MOVEMENT_STATE.MOVING || previousMovState == MOVEMENT_STATE.STOPPED) { this.anim.CrossFade("Jump High"); } break; } case MOVEMENT_STATE.JUMPINGLOW: { break; } default: { break; } } this.previousMovState = newState; }
// This wander function selects a random location around the Ai and moves towards it. // This will be update in the future to allow specific wander radius rather than "anywhere" private void Ai_Wander() { wanderTimer += Time.deltaTime; if (wanderTimer >= wanderTimeLimit) { _IsWandering = false; } else { _IsWandering = true; } if (_CanWanderAnywhere) { currentWanderPos = transform.position; } else { if (!_HasWanderPos) { currentWanderPos = transform.position; _HasWanderPos = true; } } if (_IsWandering) { anim.SetBool("Attack", false); anim.SetBool("Walking", true); if (Time.time > wanderNext) { wanderNext = Time.time + wanderTimeRate; float wanderX = Random.Range(currentWanderPos.x - wanderDistance, currentWanderPos.x + wanderDistance); float wanderZ = Random.Range(currentWanderPos.z - wanderDistance, currentWanderPos.z + wanderDistance); wanderPos = new Vector3(wanderX, currentWanderPos.y, wanderZ); } if (Vector3.Distance(transform.position, wanderPos) > 0.5f) { Ai_Movement(wanderPos, wanderSpeed); moveState = MOVEMENT_STATE.IsWandering; } else { moveState = MOVEMENT_STATE.IsIdle; } } }
private void logMoveState(MOVEMENT_STATE newState) { Debug.Log("MOVEMENT_STATE : " + this.previousMovState + "-->" + newState); }
private void Ai_Controller( ) { // Checks if following player is enabled and a player has been found if (_CanFollowPlayer && this.Ai_FindPlayer( )) { _HasWanderPos = false; // TODO: this needs to be fixed visionState = VISION_STATE.CanSeePlayer; // CHANGE THIS TO FLEE (_CanFlee) if (_IsRanged) // Is this a ranged ground unit? { if (Vector3.Distance(transform.position, Player.position) > followDistance) { moveState = MOVEMENT_STATE.IsFollowingPlayer; attackState = ATTACK_STATE.CanNotAttack; Ai_Movement(Player.position, followSpeed); } else if (_CanFlee && Vector3.Distance(transform.position, Player.position) <= attackDistance) { moveState = MOVEMENT_STATE.IsFollowingPlayer; attackState = ATTACK_STATE.CanNotAttack; Ai_Flee( ); } else { moveState = MOVEMENT_STATE.IsIdle; attackState = ATTACK_STATE.CanAttackPlayer; Ai_Rotation(Player.position); } } else if (_IsMelee) // Is this a melee ground unit? { if (Vector3.Distance(transform.position, Player.position) > followDistance) { moveState = MOVEMENT_STATE.IsFollowingPlayer; attackState = ATTACK_STATE.CanNotAttack; Ai_Movement(Player.position, followSpeed); } else if (Vector3.Distance(transform.position, Player.position) <= attackDistance) { moveState = MOVEMENT_STATE.IsIdle; attackState = ATTACK_STATE.CanAttackPlayer; Ai_Rotation(Player.position); } } Debug.DrawLine(transform.position, Player.position, Color.red); // Checks if following breadcrumbs is enabled as well as if a player was spotted and a breadcrumb has been found } else if (_CanFollowBreadcrumbs && FollowingPlayer && this.Ai_FindBreadcrumb( )) { _HasWanderPos = false; // TODO: this needs to be fixed visionState = VISION_STATE.CanSeeBreadcrumb; moveState = MOVEMENT_STATE.IsFollowingBreadcrumb; attackState = ATTACK_STATE.CanNotAttack; Ai_Movement(Breadcrumb.position, followSpeed); Debug.DrawLine(transform.position, Breadcrumb.position, Color.green); // Checks if following other ai is enabled and if an ai has been found } else if (_CanFollowAi && this.Ai_FindAi( )) { _HasWanderPos = false; // TODO: this needs to be fixed visionState = VISION_STATE.CanSeeFollowAi; moveState = MOVEMENT_STATE.IsFollowingAi; attackState = ATTACK_STATE.CanNotAttack; if (Vector3.Distance(transform.position, FollowingAi.position) > otherAiDistance) { Ai_Movement(FollowingAi.position, followSpeed); } else { moveState = MOVEMENT_STATE.IsIdle; } Debug.DrawLine(transform.position, FollowingAi.position, Color.magenta); // Checks if following other ai is enabled and if a tier two ai has been found } else if (_CanFollowAi && this.Ai_FindAiTierTwo( )) { _HasWanderPos = false; // TODO: this needs to be fixed visionState = VISION_STATE.CanSeeFollowAiTierTwo; moveState = MOVEMENT_STATE.IsFollowingAiTierTwo; attackState = ATTACK_STATE.CanNotAttack; if (Vector3.Distance(transform.position, FollowingAi.position) > otherAiDistance) { Ai_Movement(FollowingAi.position, followSpeed); } else { moveState = MOVEMENT_STATE.IsIdle; } Debug.DrawLine(transform.position, FollowingAi.position, Color.white); // Checks if wandering is enabled and if the timer has reached its limit } else if (_CanWander && wanderTimer < wanderTimeLimit) { visionState = VISION_STATE.CanSeeNothing; attackState = ATTACK_STATE.CanNotAttack; Ai_Wander( ); // Checks if patrolling is enabled and a waypoing has been found } else if (_CanPatrol && this.Ai_FindWaypoint( )) { _HasWanderPos = false; // TODO: this needs to be fixed visionState = VISION_STATE.CanSeeWaypoint; moveState = MOVEMENT_STATE.IsPatrolling; attackState = ATTACK_STATE.CanNotAttack; Ai_Movement(Waypoint.position, patrolSpeed); Debug.DrawLine(transform.position, Waypoint.position, Color.yellow); // Nothing is found, reset all variables } else { Ai_Reset( ); } }
public void stopMoving() { currentState = MOVEMENT_STATE.IDLE; }
public void UpdateMovementState(MOVEMENT_STATE newState) { movementState = newState; }