//TODO:TEAM TRAITS X2 //called only when overlapped sphere with neighbours public override Vector3 TeamSpecificSeperation(Collider[] neighbours) { Vector3 newVec = Vector3.zero; foreach (Collider neigh in neighbours) { //avoid teammates, if (neigh.gameObject.CompareTag("Environment") || neigh.gameObject.CompareTag("Ground")) { if ((transform.position - neigh.transform.position).magnitude <= playerConstants.neighbourAvoidanceRadius) { newVec += SpeedExhaustReg.NormalizeSteeringForce((transform.position - neigh.gameObject.transform.position) , playerConstants.maxSteeringForce) * playerConstants.neighbourAvoidanceWeight; } } if (neigh.gameObject.CompareTag("Gryffindor")) { Vector3 neighbourTrans = neigh.transform.position; //seperation if ((transform.position - neighbourTrans).magnitude <= playerConstants.neighbourAvoidanceRadius) { newVec += SpeedExhaustReg.NormalizeSteeringForce((transform.position - neighbourTrans) , playerConstants.maxSteeringForce) * playerConstants.neighbourAvoidanceWeight; } if (!_nearestTeammate) { _nearestTeammate = neigh.gameObject; } Vector3 nearestTeammateTrans = _nearestTeammate.transform.position; if ((neighbourTrans - nearestTeammateTrans).magnitude < (transform.position - nearestTeammateTrans).magnitude) { if ((transform.position - neighbourTrans).magnitude > 1.0f) { _nearestTeammate = neigh.gameObject; } } } } if (playerConstants.showSeperationVector) { Debug.DrawRay(transform.position, newVec, Color.green); } return(newVec); }
//MOVEMENT RELATED METHODS// //*SEPERATION NEEDS WORK //this function only changes direction //Some of this code adapted from Omar Addam (https://github.com/omaddam/Boids-Simulation) private void _generalBoidBehavior() { Vector3 accel = new Vector3(); Vector3 snitchPos = _snitchObj.transform.position; Vector3 thisPos = transform.position; //add force towards snitch accel += (snitchPos - transform.position).normalized; accel += SpeedExhaustReg.NormalizeSteeringForce(snitchPos - thisPos, playerConstants.maxSteeringForce) * playerConstants.snitchFollowWeight; if (playerConstants.showVectorTowardSnitch) { Debug.DrawRay(transform.position, accel, Color.red); } //add force away from neighbours and environment - seperation Collider[] neighbours = Physics.OverlapSphere(transform.position, playerConstants.neighbourDetectionRadius); if (neighbours.Length > 0) { accel += TeamSpecificSeperation(neighbours); } //avoid environemnt accel += SpeedExhaustReg.NormalizeSteeringForce(AvoidCollisions(), playerConstants.maxSteeringForce) * playerConstants.environmentAvoidanceWeight; //adjust speed based on exhaustion float tempMaxVel = maxVelocity; if ((maxExhaust - currentExhaust) <= 8) { tempMaxVel = maxVelocity * Random.Range(0.3f, 0.8f); } //add force based on team-specific traits (i.e. crunkness) accel += TeamSpecificBehavior(); //create new velocity based on calculated acceleration Vector3 newVel = _rb.velocity; newVel += accel * Time.deltaTime; //clamp velocity newVel = newVel.normalized * Mathf.Clamp(newVel.magnitude, 0.0f, tempMaxVel); //apply velocity _rb.velocity = newVel; transform.forward = _rb.velocity.normalized; _agentVector = newVel; }
public override Vector3 TeamSpecificBehavior() { Vector3 newVec = Vector3.zero; //vortexing behavior /* * if(slythTraits.showVortexingVector) * Debug.DrawLine(transform.position,_vortexMiddle,Color.magenta); */ newVec += SpeedExhaustReg.NormalizeSteeringForce(CalculateVortexingVelocity(), playerConstants.maxSteeringForce) * slythTraits.vortexWeighting; return(newVec); }
private void _handleExhaustionTick() { //tick exhaustion if timer has elapsed _exhaustTimer += Time.deltaTime; if (_exhaustTimer > playerConstants.exhastionTickFreq) { //calculate new exhaust currentExhaust = SpeedExhaustReg.TickExhaust(currentExhaust, _rb.velocity.magnitude, maxVelocity, playerConstants); Mathf.Clamp(currentExhaust, 0.0f, maxExhaust); if (currentExhaust >= maxExhaust) { TransitionState(PlayerState.Unconscious); } _exhaustTimer = 0; } }
public override Vector3 TeamSpecificBehavior() { Vector3 newVec = Vector3.zero; //calculate crunkness vector newVec += SpeedExhaustReg.NormalizeSteeringForce(CalculateCrunkVector(), playerConstants.maxSteeringForce) * gryffTraits.crunknessWeighting; //BUDDY SYSTEM newVec += SpeedExhaustReg.NormalizeSteeringForce((_nearestTeammate.gameObject.transform.position - transform.position) * _buddyUpFactor, playerConstants.maxSteeringForce) * gryffTraits.buddySystemWeighting; if (gryffTraits.showBuddyVector) { Debug.DrawLine(transform.position, _nearestTeammate.gameObject.transform.position, Color.cyan); } return(newVec); }
private void FixedUpdate() { Vector3 accel = new Vector3(); _timer += Time.deltaTime; if (_timer >= snitchSettings.directionTimer) { Vector3 randPoint = Random.onUnitSphere; Vector3 randDir = (randPoint - transform.position) * snitchSettings.snitchSpeed; accel += randDir; accel += SpeedExhaustReg.NormalizeSteeringForce(randDir, snitchSettings.maxSteeringForce); _timer = 0.0f; if (snitchSettings.showRandomVector) { Debug.DrawRay(transform.position, randPoint * 5.0f, Color.yellow); } } accel += SpeedExhaustReg.NormalizeSteeringForce(AvoidCollisions(), snitchSettings.maxSteeringForce) * snitchSettings.environmentAvoidanceWeighting; Vector3 newVelocity = _rb.velocity; newVelocity += accel * Time.deltaTime; //clamp velocity newVelocity = newVelocity.normalized * Mathf.Clamp(newVelocity.magnitude, snitchSettings.minVelocity, snitchSettings.maxVelocity); _rb.velocity = newVelocity; if (snitchSettings.showDirectionVector) { Debug.DrawRay(transform.position, newVelocity, Color.white); } transform.forward = _rb.velocity.normalized; }
//todo team traits public override Vector3 TeamSpecificSeperation(Collider[] neighbours) { Vector3 newVec = Vector3.zero; //for calculating vortex position int numTeammates = 1; Vector3 centrePos = transform.position; foreach (Collider neigh in neighbours) { //avoid teammates, ground and environment if (neigh.gameObject.CompareTag("Environment") || neigh.gameObject.CompareTag("Ground")) { if ((neigh.transform.position - transform.position).magnitude <= playerConstants.neighbourAvoidanceRadius) { newVec += SpeedExhaustReg.NormalizeSteeringForce((transform.position - neigh.gameObject.transform.position), playerConstants.maxSteeringForce) * playerConstants.neighbourAvoidanceWeight; } } if (neigh.gameObject.CompareTag("Slytherin")) { //seperation if ((neigh.transform.position - transform.position).magnitude <= playerConstants.neighbourAvoidanceRadius) { newVec += SpeedExhaustReg.NormalizeSteeringForce((transform.position - neigh.gameObject.transform.position), playerConstants.maxSteeringForce) * playerConstants.neighbourAvoidanceWeight; } //determine center of local vortex numTeammates++; centrePos += neigh.gameObject.transform.position; } else if (neigh.gameObject.CompareTag("Gryffindor")) { if ((neigh.transform.position - transform.position).magnitude <= slythTraits.bruiserBludgeonRadius) //will try to ram gryffindor depending how much of a brute this agent is { float tempBruiserWeight = _bruiserLevel * slythTraits.bruiserWeighting; newVec += SpeedExhaustReg.NormalizeSteeringForce( (neigh.gameObject.transform.position - transform.position), playerConstants.maxSteeringForce) * tempBruiserWeight; } if (slythTraits.showBruiserVector) { Debug.DrawLine(transform.position, neigh.gameObject.transform.position, Color.yellow); } } if (playerConstants.showNeighbourLineTraces) { Debug.DrawLine(transform.position, neigh.transform.position, Color.magenta, duration: 2.0f); } } if (playerConstants.showSeperationVector) { Debug.DrawRay(transform.position, newVec, Color.green); } _vortexMiddle = centrePos / numTeammates; return(newVec); }