void MoveToTarget() { Vector3 _acceleration = new Vector3(0.0f, 0.0f, 0.0f); var targetlist = _trainData.ListTurret; int targetSize = targetlist.Length; int randomtarget = Random.Range(0, targetSize); targetPos = targetlist[randomtarget].gameObject.transform.position; Vector2 destination = new Vector2(targetPos.x, transform.position.y); _acceleration = BehaviourUpdate.BehaviourUpdated(SeekBehaviour.SeekMove(transform, destination, enemyData.MaxSpeed), enemyData.SeekWeight); _velocity += _acceleration * Time.deltaTime; float dis = float.MinValue; if (Mathf.Abs(transform.position.x - destination.x) < 0.1f) { mCurrentState = State.Charging; _nextAttackTime = Time.time + enemyData.AttackDelay + Random.Range(-enemyData.AttackDelay * 0.1f, enemyData.AttackDelay * 0.1f); } else { transform.position += _velocity * Time.deltaTime; } }
void FlyAndShootUpdate() { //Movement Vector3 _acceleration = new Vector3(0.0f, 0.0f, 0.0f); //_acceleration += WanderBehavior.Calculate(gameobject, weight); _acceleration = BehaviourUpdate.BehaviourUpdated(WanderBehavior.WanderMove(this.transform, enemyData.WanderRadius, enemyData.WanderDistance, enemyData.WanderJitter, 3.0f), enemyData.WanderBehaviorWeight); //_acceleration += (Vector3)(BehaviourUpdate.BehaviourUpdated(WallAvoidance.WallAvoidanceCalculation(transform,_botLeftBound.position.x,_topRightBound.position.x,_topRightBound.position.y,_botLeftBound.position.y),enemyData.WallAvoidWeight)); _velocity += _acceleration * Time.deltaTime; if (_velocity.magnitude > enemyData.MaxSpeed) { _velocity.Normalize(); _velocity *= enemyData.MaxSpeed; } if (transform.position.x < _botLeftBound.position.x) { _velocity.x *= -1; } if (transform.position.x > _topRightBound.position.x) { _velocity.x *= -1; } if (transform.position.y < _topRightBound.position.y) { _velocity.y *= -1; } if (transform.position.y > _botLeftBound.position.y) { _velocity.y *= -1; } transform.position += _velocity * Time.deltaTime; //Shooting if (_nextAttackTime < Time.time) { animator.SetBool("Shoot", true); Invoke("unplayAnimation", 0.5f); //var targetlist = LevelManager.Instance.Train.GetTurrets(); _nextAttackTime = Time.time + enemyData.AttackDelay + Random.Range(-enemyData.AttackDelay * 0.1f, enemyData.AttackDelay * 0.1f); Invoke("delayshoot", 0.75f); } if (_nextAttackTime < (Time.time + enemyData.AttackDelay - enemyData.AttackDelay * 0.1f)) { boom.SetActive(false); } else { boom.SetActive(true); } }
void WanderIdle() { //Movement Vector3 _acceleration = new Vector3(0.0f, 0.0f, 0.0f); _acceleration = BehaviourUpdate.BehaviourUpdated(WanderBehavior.WanderMove(this.transform, enemyData.WanderRadius, enemyData.WanderDistance, enemyData.WanderJitter, 1.0f), enemyData.WanderBehaviorWeight); _velocity += _acceleration * Time.deltaTime; if (_velocity.magnitude > enemyData.MaxSpeed) { _velocity.Normalize(); _velocity *= enemyData.MaxSpeed; } if (transform.position.x > _botLeftBound.position.x + 1.0f) { _velocity.x *= -1; } if (transform.position.x < _topRightBound.position.x - 1.0f) { _velocity.x *= -1; } if (transform.position.y < _topRightBound.position.y - 2.0f) { _velocity.y *= -1; } if (transform.position.y > _botLeftBound.position.y + 2.0f) { _velocity.y *= -1; } transform.position += _velocity * Time.deltaTime; //Shooting if (_nextAttackTime < Time.time) { mCurrentState = State.MoveToTarget; // _nextAttackTime = enemyData.AttackDelay + Time.time; } }
public void GroupBehaviours() { Vector3 _acceleration = new Vector3(0.0f, 0.0f, 0.0f); foreach (var agent in swarmNeighbors) { if (!agent.Attacking) { _acceleration = BehaviourUpdate.BehaviourUpdated(WanderBehavior.WanderMove(agent.transform, enemyData.WanderRadius, enemyData.WanderDistance, enemyData.WanderJitter, 1.0f), enemyData.WanderBehaviorWeight); _acceleration += (Vector3)BehaviourUpdate.BehaviourUpdated(CohesionBehavior.CalculateMove(agent.transform, swarmNeighborsTrans), enemyData.CohesionBehaviorWeight); _acceleration += (Vector3)BehaviourUpdate.BehaviourUpdated(SeparationBehavior.SeparationMove(agent.transform, swarmNeighborsTrans, enemyData.SeparationBehaviorRadius), enemyData.SeparationBehaviorWeight); _acceleration += (Vector3)BehaviourUpdate.BehaviourUpdated(AlignmentBehavior.CalculateMove(agent.transform, swarmNeighborsTrans), enemyData.AlignmentBehaviorWeight); agent.Velocity += _acceleration * Time.deltaTime; if (agent.Velocity.magnitude > enemyData.MaxSpeed) { agent.Velocity.Normalize(); agent.Velocity *= enemyData.MaxSpeed; } if (agent.transform.position.x < _bottomLeft.position.x) { agent.Velocity *= -1; } if (agent.transform.position.x > _topright.position.x) { agent.Velocity *= -1; } if (agent.transform.position.y < _topright.position.y) { agent.Velocity *= -1; } if (agent.transform.position.y > _bottomLeft.position.y) { agent.Velocity *= -1; } //agent.transform.position += agent.Velocity * Time.deltaTime; } else { _acceleration = BehaviourUpdate.BehaviourUpdated(SeekBehaviour.SeekMove(agent.transform, agent.Target, enemyData.Swarm_AttackSpeed), enemyData.SeekBehaviorWeight); agent.Velocity += _acceleration * Time.deltaTime; } Vector3 deltaPos = agent.Velocity * Time.deltaTime; if (deltaPos.x == 0 && deltaPos.y == 0) { Debug.Log("Enemy is stuck!"); } agent.transform.position += agent.Velocity * Time.deltaTime; //_acceleration += (Vector3)(BehaviourUpdate.BehaviourUpdated(WallAvoidance.WallAvoidanceCalculation(agent.transform, _bottomLeft.position.x, _topright.position.x, _topright.position.y, _bottomLeft.position.y), enemyData.WallAvoidWeight)); } //transform.position += _velocity * Time.deltaTime; // { // move = BehaviourUpdate.BehaviourUpdated(CohesionBehavior.CalculateMove(agent.transform, swarmNeighbors), 5.0f); // move *= speed; // if (move.sqrMagnitude > squareMaxSpeed) // { // move = move.normalized * maxSpeed; // } // agent.transform.position += (Vector3)move * Time.deltaTime; // } }
void FlyAndShootUpdate() { //Movement Vector3 _acceleration = new Vector3(0.0f, 0.0f, 0.0f); //_acceleration += WanderBehavior.Calculate(gameobject, weight); _acceleration = BehaviourUpdate.BehaviourUpdated(WanderBehavior.WanderMove(this.transform, enemyData.WanderRadius, enemyData.WanderDistance, enemyData.WanderJitter, 3.0f), enemyData.WanderBehaviorWeight); //_acceleration += WallAvoidance.Calculate(gameobject, weight); //_acceleration += (Vector3)(BehaviourUpdate.BehaviourUpdated(WallAvoidance.WallAvoidanceCalculation(transform,_botLeftBound.position.x,_topRightBound.position.x,_topRightBound.position.y,_botLeftBound.position.y),enemyData.WallAvoidWeight)); _velocity += _acceleration * Time.deltaTime; if (_velocity.magnitude > enemyData.MaxSpeed) { _velocity.Normalize(); _velocity *= enemyData.MaxSpeed; } //if (Mathf.Abs(transform.position.x - _botLeftBound.position.x) > 1.0f) if (transform.position.x < _botLeftBound.position.x) { //_velocity = new Vector3(-_velocity.x, _velocity.y, _velocity.z); _velocity.x *= -1; } //if (Mathf.Abs(transform.position.x - _topRightBound.position.x) > 1.0f) if (transform.position.x > _topRightBound.position.x) { //_velocity = new Vector3(-_velocity.x, _velocity.y, _velocity.z); _velocity.x *= -1; } //if (Mathf.Abs(transform.position.y - _topRightBound.position.y) > 1.0f) if (transform.position.y < _topRightBound.position.y) { //_velocity = new Vector3(_velocity.x, -_velocity.y, _velocity.z); _velocity.y *= -1; } //if (Mathf.Abs(transform.position.y - _botLeftBound.position.y) > 1.0f) if (transform.position.y > _botLeftBound.position.y) { //_velocity = new Vector3(_velocity.x, -_velocity.y, _velocity.z); _velocity.y *= -1; } transform.position += _velocity * Time.deltaTime; //Shooting if (_nextAttackTime < Time.time) { var targetlist = _trainData.ListTurret; int targetSize = targetlist.Length; int randomtarget = Random.Range(0, targetSize); _nextAttackTime = Time.time + enemyData.AttackDelay + Random.Range(-enemyData.AttackDelay * 0.1f, enemyData.AttackDelay * 0.1f); GameObject projectile = _objectPoolManager.GetObjectFromPool("BasicEnemy_Projectile"); projectile.transform.position = transform.position; Vector3 targetPos = targetlist[randomtarget].gameObject.transform.position; projectile.SetActive(true); projectile.GetComponent <EnemyProjectile>().SetData(targetPos, EnemyTypeCheck.Type.Basic); } }