/// <summary> /// Changes values upon entry. /// </summary> public override void Enter() { AIagent.SetDestination(GetDistanceToRun()); Prey = null; PreyLocated = false; AIagent.speed = MoveSpeed; }
/// <summary> /// Sets a new destination for the NavMeshAgent owner. /// </summary> private void SetNewDestination() { Vector3 position = new Vector3(Random.Range(-patrolArea, patrolArea), 0, Random.Range(-patrolArea, patrolArea)); AIagent.SetDestination(Position.position + position); Destination = AIagent.destination; }
/// <summary> /// Updates navmesh destination to the player's position and checks distance between game object and player. /// Swaps to <see cref="CowMoveState"/> if the distance becomes to great. /// </summary> public override void Update() { base.Update(); isFollowing += Time.deltaTime; if (isFollowing > 0.5) { AIagent.SetDestination(Player.transform.position); if (Vector3.Distance(Position.position, Player.transform.position) > 10) { AIagent.speed = MovementSpeed * 1.6f; } else { AIagent.speed = MovementSpeed; } isFollowing = 0; } if (Vector3.Distance(Position.position, Player.transform.position) > FollowDistance) { //Debug.Log(Vector3.Distance(Position.position, Player.transform.position) > FollowDistance); //Debug.Log(FollowDistance); //Debug.Log(Vector3.Distance(Position.position, Player.transform.position)); owner.TransitionTo <CowMoveState>(); } }
private void CalculateNewPatrol() { /* * float distance = Vector3.Distance(Position.position, WolfPack.prey.transform.position); * Vector3 direction = WolfPack.prey.transform.position - Position.position; * Vector3 newPath = Vector3.zero; * if ( distance > 10) * { * distance -= 10f; * newPath = direction.normalized * distance; * //move in direction of angle * * * //move closer * } * else if(distance < 9) * { * distance = 10- distance; * newPath = direction.normalized * distance; * //move in direction of angle * //move further away * }*/ Vector3 offset = Position.position - centerPosition; Vector3 direction = Vector3.Cross(offset, Vector3.up); direction *= angle; //ApplyFlockBehaviour(); AIagent.SetDestination(centerPosition + direction); Destination = AIagent.destination; }
/// <summary> /// Starts a timer for when the object is gonna transition to <see cref="AlphaObserveState"/> and handles conditions for state swapping. /// </summary> public override void Update() { //ApplyFlockBehaviour(); newPathTimer += Time.deltaTime; Destination = AIagent.destination; base.Update(); setVelocity(); if (PlayerHasFire) { owner.TransitionTo <AlphaFleeState>(); } else if (!PreyLocated) { ChaseSprite.SetActive(false); owner.TransitionTo <AlphaPatrolState>(); } else if (newPathTimer > 0.35 && CheckRemainingDistance(Prey.transform.position, 8f) && CanSeePrey()) { // owner.TransitionTo<WolfAttackPatrolState>(); owner.TransitionTo <AlphaObserveState>(); } else if (newPathTimer > 0.35) { if (CanSeePrey()) { AIagent.SetDestination(Prey.transform.position); } newPathTimer = 0; } }
/// <summary> /// Sets values upon entry. /// </summary> public override void Enter() { AIagent.speed = Speed * 1.5f; FleeToGnomergan(); AIagent.SetDestination(Position.position + Gnomergan); despawned = false; }
/// <summary> /// Sets a new destination within the area of the animal pen. /// </summary> private void SetDestination() { Vector3 destination; Vector3 randomLocationInPen = new Vector3(Random.Range(-penArea, penArea), 0, (Random.Range(-penArea, penArea))); destination = Pen.transform.position + randomLocationInPen; AIagent.SetDestination(destination); }
/// <summary> /// Calculates a new path to circle around the current target. /// </summary> private void CalculateNewPatrol() { Vector3 offset = Position.position - centerPosition; Vector3 direction = Vector3.Cross(offset * 4f, Vector3.up); direction *= -1; AIagent.SetDestination(centerPosition + (direction)); Destination = AIagent.destination; }
/// <summary> /// Removes the cow from various lists and then plays a small animation before removal. /// </summary> public override void Enter() { AIagent.SetDestination(owner.gameObject.transform.position); if (GameComponents.FollowingCowsList.Contains(owner.gameObject)) { GameComponents.FollowingCowsList.Remove(owner.gameObject); } GameComponents.FairGameList.Remove(owner.gameObject); Position.rotation = Quaternion.Euler(0, 0, 90); Destroy(owner.gameObject, 3f); }
/// <summary> /// Sets the navmesh agents destination to the targets position and swaps to <see cref="GnomeAnnoyState"/> when within 1 units distance of the target. /// </summary> public override void Update() { if (Target != null) { AIagent.SetDestination(Target.transform.position);//.x, 0, Target.transform.position.z)); } if (AIagent.remainingDistance < 1f) { owner.TransitionTo <GnomeAnnoyState>(); } }
// Start is called before the first frame update public override void Enter() { AIagent.SetDestination(Position.position); charge = owner.transform.position - WolfPack.prey.transform.position; moveSpeed = 10f; Debug.Log(owner.name + " entered AttackState"); AIagent.speed = moveSpeed; charge = charge.normalized * chargeDistance; //ApplyFlockBehaviour(); AIagent.SetDestination(owner.transform.position - charge); Destination = AIagent.destination; }
/// <summary> /// Sets a destination within a radius of <see cref="patrolArea"/> from the game objects starting position. /// </summary> private void SetNewDestination() { currentTry = 0; do { position = new Vector3(Random.Range(-patrolArea, patrolArea), 0, Random.Range(-patrolArea, patrolArea)); currentTry++; } while (position.magnitude < 10 && currentTry < 10); position = StartPosition + position; AIagent.SetDestination(position); }
private void SetNewDestination() { Vector3 position; int currentTry = 0; do { position = new Vector3(Random.Range(-patrolArea, patrolArea), 0, Random.Range(-patrolArea, patrolArea)); currentTry++; } while (Vector3.Dot(position - owner.transform.position, WolfPack.transform.position - owner.transform.position) < 1 && currentTry < 100); AIagent.SetDestination(position); Destination = AIagent.destination; }
/// <summary> /// Sets values and fleeing position upon enter. /// </summary> public override void Enter() { AIagent.speed = MovementSpeed * 1.5f; Vector3 position; int currentTry = 0; do { position = new Vector3(Random.Range(-30, 30), 0, Random.Range(-30, 30)); currentTry++; } while (position.magnitude < 15f && currentTry < 10f); AIagent.SetDestination(Position.position + position); }
/// <summary> /// Adds <see cref="Time.deltaTime"/> to timer in order to create a cooldown on how often the game object can attack. /// </summary> public override void Update() { timer += Time.deltaTime; if (CheckRemainingDistance(Target.transform.position, 3f)) { if (timer >= cooldown) { Target.GetComponent <CowSM>().AttackTheCow(0); timer = 0f; } } AIagent.SetDestination(Target.transform.position); }
/// <summary> /// Checks if the Player has a torch out, if it has lost it's target and if it is close enough to attack. /// Then swaps state depending on what condition is true /// </summary> public override void Update() { AIagent.SetDestination(Prey.transform.position); if (PlayerHasFire) { owner.TransitionTo <AlphaFleeState>(); } else if (!PreyLocated) { owner.TransitionTo <AlphaPatrolState>(); } else if (CheckRemainingDistance(Prey.transform.position, 3f)) { if (Prey.gameObject.tag == "Cow") { Prey.GetComponent <CowSM>().AttackTheCow((int)Damage); } else if (Prey.gameObject.tag == "Player") { Prey.GetComponent <PlayerStateMashine>().GetAttacked((int)Damage); DamageEventInfo dei = new DamageEventInfo { damage = Damage }; EventHandeler.Current.FireEvent(EventHandeler.EVENT_TYPE.Damage, dei); Debug.Log("Damage is done by wolf, dmg " + Damage); } if (Prey == null) { PreyLocated = false; } owner.TransitionTo <AlphaObserveState>(); } base.Update(); //check it out /* * NavMeshPath path =null; * NavMesh.CalculatePath(Vector3.zero, Vector3.up, NavMesh.AllAreas, path); * path.corners.ToList().ForEach(p => Position); */ setVelocity(); }
private void SetDestination() { GameObject followWolf = null; foreach (GameObject wolf in WolfPack.wolves) { if (Vector3.Distance(wolf.transform.position, WolfPack.prey.transform.position) < Vector3.Distance(Position.position, WolfPack.prey.transform.position)) { followWolf = wolf; } } if (followWolf != null) { float rand = Random.Range(0.8f, 1.2f); AIagent.SetDestination(followWolf.transform.position * rand); } else { AIagent.SetDestination(WolfPack.prey.transform.position); } }
// Start is called before the first frame update public override void Enter() { isInDen = false; AIagent.speed = MoveSpeed * 1.5f; AIagent.SetDestination(DenLocation); }
/// <summary> /// Sets a new destination within a radius of 2 /// </summary> private void SetStoppedDestination() { position = new Vector3(Random.Range(-stoppedPatrolArea, stoppedPatrolArea), 0, Random.Range(-stoppedPatrolArea, stoppedPatrolArea)); AIagent.SetDestination(Position.position + position); }
/// <summary> /// Increases the movement speed of the game object and sets a new destination for the navmesh. /// </summary> public override void Enter() { AIagent.speed = MovementSpeed * 2f; AIagent.SetDestination(SearchPosition); }
/// <summary> /// Sets the game objects destination to it's target's position. /// </summary> public void SetNewDestination() { AIagent.SetDestination(Target.transform.position); }
/// <summary> /// resets the position and changes the value of Attacked /// </summary> public override void Exit() { AIagent.SetDestination(Position.position); Attacked = false; }
/// <summary> /// Stops the navmesh agent. /// </summary> public override void Enter() { owner.GetComponent <Renderer>().material = DayMaterial; AIagent.SetDestination(owner.transform.position); AIagent.isStopped = true; }
/// <summary> /// Sets a random destination within a radius of 2 within the assigned destination. /// </summary> public override void Enter() { AIagent.speed = MovementSpeed * 1.5f; randomLocation = new Vector3(Random.Range(-randomArea, randomArea), 0, Random.Range(-randomArea, randomArea)) + GoToLocation; AIagent.SetDestination(randomLocation); }