private void ThrowBall() { cAud.FBallThrown(mThrowChrg.Val); PROJ_Football clone = Instantiate(PF_Football, mThrowPoint.transform.position, transform.rotation); // now we add in the innacuracy. // x inaccuracy feels better than y inaccuracy, which can look really stupid. float fXAcc = Random.Range(-GB_TotalInaccuracy.Val, GB_TotalInaccuracy.Val) / 100f; float fYAcc = Random.Range(-GB_TotalInaccuracy.Val, GB_TotalInaccuracy.Val) / 100f; fYAcc /= IO_Settings.mSet.lInaccuracyBias; Vector3 vThrowDir = cCam.transform.forward; vThrowDir.x += fXAcc; vThrowDir.y += fYAcc; vThrowDir = Vector3.Normalize(vThrowDir); Debug.Log("Throw Dir: " + vThrowDir); Debug.Log("Throw Charge: " + mThrowChrg.Val); Debug.Log("Throw Speed Maximum: " + IO_Settings.mSet.lPlayerData.mThrowSpd); clone.GetComponent <Rigidbody>().velocity = vThrowDir * mThrowChrg.Val * IO_Settings.mSet.lPlayerData.mThrowSpd; mThrowChrg.Val = 0f; mThrowState = PC_THROW_STATE.S_RECOVERING; TDC_EventManager.FBroadcast(TDC_GE.GE_QB_ReleaseBall); SetInaccuraciesToZero(); Invoke("CanThrowAgain", 1.0f); }
void InterceptBall() { PROJ_Football fBallRef = FindObjectOfType <PROJ_Football>(); if (fBallRef == null) { Debug.Log("No football in scene, still trying to intercept"); return; } Vector3 spotToMoveTo = new Vector3(); Vector3 dis = fBallRef.transform.position - transform.position; dis = Vector3.Normalize(dis); // we need to find the spot when the ball will be low enough for us to affect. // since it's a parabola, we should get two points representing that height. Vector3 ballvel = fBallRef.GetComponent <Rigidbody>().velocity; float mag = Vector3.Magnitude(ballvel); spotToMoveTo = CalcMoveSpot(fBallRef); // now we just move to the spot. cRigid.velocity = cAthlete.mSpd * Vector3.Normalize(spotToMoveTo - transform.position); }
private void OnTriggerEnter(Collider other) { if(other.GetComponent<GM_Endzone>() != null) { mInEndzone = true; } if(other.GetComponent<PROJ_Football>() != null){ mCaughtBall = true; HitTarget.Raise(null); if(cRunner != null){ cRunner.mActivated = true; PROJ_Football fBallRef = FindObjectOfType<PROJ_Football>(); cRunner.rFootball = fBallRef; Rigidbody rigid = fBallRef.GetComponent<Rigidbody>(); rigid.velocity = Vector3.zero; rigid.useGravity = false; rigid.detectCollisions = false; fBallRef.transform.parent = transform.parent; } // when we've caught the ball, we de-activate our "follow your route" script. if(cRouteFollow != null) { cRouteFollow.mActive = false; } } }
// Now we calculate how long it's going to take to get to that spot. public float FCalcInterceptTime(float fHeightOfInfluence = 1f) { PROJ_Football fBallRef = FindObjectOfType <PROJ_Football>(); if (fBallRef == null) { // Debug.Log("No football in scene. Time is infinite."); return(0f); } Vector3 vBallVel = fBallRef.GetComponent <Rigidbody>().velocity; float mag = Vector3.Magnitude(vBallVel); // ----------------------------------- First if statement is if the ball is already below our hands, and is going down, or it's right there already. if (fBallRef.transform.position.y < fHeightOfInfluence) { return(0f); } else { // ----------- Here we have to calculate the spot, since the ball is unfortunately not going down already and is not close to us. float yDisToGo = fBallRef.transform.position.y - fHeightOfInfluence; float fFinalVel = Mathf.Sqrt(Mathf.Abs(vBallVel.y * vBallVel.y + 2 * Physics.gravity.magnitude * yDisToGo)) * -1f; float fTm = Mathf.Abs((fFinalVel - vBallVel.y)) / Physics.gravity.magnitude; return(fTm); } }
public bool FCheckIfBallThrown() { PROJ_Football f = FindObjectOfType <PROJ_Football>(); if (f != null) { return(true); } return(false); }
// something feels vaguely off with this. private void OnCollisionEnter(Collision collision) { if (collision.transform.GetComponent <AI_Tackler>()) { // now we want to release the ball from our grasp. PROJ_Football fBall = GetComponentInChildren <PROJ_Football>(); if (fBall) { GE_Tackled.Raise(null); mActivated = false; fBall.transform.parent = null; } } }
public Vector3 FCalcInterceptSpot(float fHeightOfInfluence = 1f) { PROJ_Football fBallRef = FindObjectOfType <PROJ_Football>(); if (fBallRef == null) { // Debug.Log("No football in scene. Intercept will have issues."); return(Vector3.zero); } Vector3 vSpotToMoveTo = new Vector3(); Vector3 vBallVel = fBallRef.GetComponent <Rigidbody>().velocity; float mag = Vector3.Magnitude(vBallVel); // ----------------------------------- First if statement is if the ball is already below our hands, and is going down, or it's right there already. if (fBallRef.transform.position.y < fHeightOfInfluence) { if (vBallVel.y <= 0f || Vector3.Distance(transform.position, fBallRef.transform.position) < 1f) { return(fBallRef.transform.position); } } else { // ----------- Here we have to calculate the spot, since the ball is unfortunately not going down already and is not close to us. float yDisToGo = fBallRef.transform.position.y - fHeightOfInfluence; float fFinalVel = Mathf.Sqrt(Mathf.Abs(vBallVel.y * vBallVel.y + 2 * Physics.gravity.magnitude * yDisToGo)) * -1f; float fTm = Mathf.Abs((fFinalVel - vBallVel.y)) / Physics.gravity.magnitude; Vector3 vFwdComp = vBallVel; vFwdComp.y = 0f; vSpotToMoveTo = fBallRef.transform.position + vFwdComp * fTm; vSpotToMoveTo.y = 0f; Instantiate(PF_SpotGFX, vSpotToMoveTo, transform.rotation); return(vSpotToMoveTo); } return(Vector3.zero); }
public Vector3 CalcInterceptSpot(PROJ_Football fBallRef) { Vector3 ballVel = fBallRef.GetComponent <Rigidbody>().velocity; Vector3 spotToMoveTo = new Vector3(); float yDisToGo = fBallRef.transform.position.y - mHeightOfInfluence; float finalVel = Mathf.Sqrt(Mathf.Abs(ballVel.y * ballVel.y + 2 * Physics.gravity.magnitude * yDisToGo)) * -1f; // kind of cheating, since we have a negative y vel, which Sqrt ruins float tm = Mathf.Abs((finalVel - ballVel.y)) / Physics.gravity.magnitude; // now we calc the spot in that forward vector. // lol, just chop out the y comp Vector3 fwdComp = ballVel; fwdComp.y = 0f; spotToMoveTo = fBallRef.transform.position + fwdComp * tm; spotToMoveTo.y = 0f; return(spotToMoveTo); }
// Ignores other players. They find the shortest path based on the football velocity and move there. void InterceptBallAssumingNoHeight() { // This is slow, but it's decent for debugging. // for now we can just hack it with the football.transform.right vector, but it will get more complicated later. PROJ_Football fBallRef = FindObjectOfType <PROJ_Football>(); Vector3 dis = fBallRef.transform.position - transform.position; dis = Vector3.Normalize(dis); // go to the right. if (Vector3.Dot(fBallRef.transform.right, dis) >= 0f) { cRigid.velocity = cAthlete.mSpd * fBallRef.transform.right; } else { cRigid.velocity = cAthlete.mSpd * -fBallRef.transform.right; } }
public Vector3 CalcMoveSpot(PROJ_Football fBallRef) { Vector3 ballVel = fBallRef.GetComponent <Rigidbody>().velocity; if (fBallRef.transform.position.y < mHeightOfInfluence) { if (ballVel.y <= 0f || Vector3.Distance(transform.position, fBallRef.transform.position) < 1f) { return(fBallRef.transform.position); } else { // theoretically I should be figuring out where the ball lands and then going there, but I just don't want to. return(CalcInterceptSpot(fBallRef)); } } else { return(CalcInterceptSpot(fBallRef)); } }
// Super prototype-y, disable pc cam, enable football cam. public void E_BallThrown() { mBallThrown = true; if (mMakeCamFollowBall) { PROJ_Football refF = FindObjectOfType <PROJ_Football>(); if (refF == null) { return; } refF.FActivateCam(); } // ------------------ Destroy all the turrets projectiles. PP_Projectile[] balls = FindObjectsOfType <PP_Projectile>(); foreach (PP_Projectile b in balls) { Destroy(b.gameObject); } }