// Let's say that when you're not throwing, you can limit the strength of a throw, by pressing shift. private void RUN_NotThrowing() { if (Input.GetMouseButton(0)) { // mThrowMax.Val = IO_Settings.mSet.lPlayerData.mThrowSpd; TDC_EventManager.FBroadcast(TDC_GE.GE_QB_StartWindup); cAud.mThrowStart.Play(); mThrowStartAngle = cCam.transform.forward; mThrowState = PC_THROW_STATE.S_CHARGING; // Start the throw at not zero. mThrowChrg.Val = 8f / IO_Settings.mSet.lPlayerData.mThrowSpd; } // Limit the power of a throw, or set it back. Actually, you can do this when charging as well. if (Input.GetKey(KeyCode.LeftShift)) { mThrowMax.Val -= Time.deltaTime * 10f; } if (Input.GetKeyDown(KeyCode.LeftControl)) { mThrowMax.Val = IO_Settings.mSet.lPlayerData.mThrowSpd; } }
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); }
// They clutch the ball and decide not to throw. public void E_ThrowStopped() { mThrowMax.Val = IO_Settings.mSet.lPlayerData.mThrowSpd; mThrowState = PC_THROW_STATE.S_RECOVERING; SetInaccuraciesToZero(); mThrowChrg.Val = 0f; Invoke("CanThrowAgain", 1.0f); }
private void RUN_ChargingThrow() { // RMB stops throw if (Input.GetMouseButton(1)) { TDC_EventManager.FBroadcast(TDC_GE.GE_QB_StopThrow); cAud.mThrowCancel.Play(); return; } // Alright, this is what needs to be changed. Throw power should not charge linearly, it should charge logarithmically. float fChrgPct = IO_Settings.mSet.lPlayerData.mThrowSpd * mThrowChrg.Val / mThrowMax.Val; float fChargeAmt = Time.deltaTime / IO_Settings.mSet.lPlayerData.mReleaseTime; fChargeAmt *= (mThrowMax.Val) / IO_Settings.mSet.lPlayerData.mThrowSpd; // the slower they want to throw, the slower it charges. // float fChargeAmt = Time.deltaTime / 5f; fChargeAmt -= fChargeAmt * (fChrgPct * fChrgPct); // gives us right side of bell curve. // but now we also have to factor in that we charge faster when closer to 0. // fChargeAmt *= (1-mThrowChrg.Val) * 2f; // so when at 0, x as fast. When at 1, 0 charge speed. mThrowChrg.Val += fChargeAmt; if ((mThrowChrg.Val * IO_Settings.mSet.lPlayerData.mThrowSpd) > (mThrowMax.Val * 0.98f)) { mThrowState = PC_THROW_STATE.S_FULLYCHARGED; mTimeThrowCharged = Time.time; } // Now handle the look inaccuracy mThrowAngle.Val = cCam.transform.forward; HandleThrowModifiers(); if (Input.GetMouseButtonUp(0)) { ThrowBall(); } // Limit the power of a throw, or set it back. Actually, you can do this when charging as well. if (Input.GetKey(KeyCode.LeftShift)) { mThrowMax.Val -= Time.deltaTime * 10f; } if (Input.GetKeyDown(KeyCode.LeftControl)) { mThrowMax.Val = IO_Settings.mSet.lPlayerData.mThrowSpd; } }
// Start is called before the first frame update void Start() { cRigid = GetComponent <Rigidbody>(); cCam = GetComponentInChildren <PC_Camera>(); cAud = GetComponentInChildren <AD_Player>(); mState = PC_STATE.SINACTIVE; mThrowState = PC_THROW_STATE.SNOT_THROWING; mThrowChrg.Val = 0f; mThrowMax.Val = IO_Settings.mSet.lPlayerData.mThrowSpd; Debug.Log("Charge now: " + mThrowChrg.Val); Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; TDC_EventManager.FAddHandler(TDC_GE.GE_QB_StopThrow, E_ThrowStopped); SetInaccuraciesToZero(); }
private void CanThrowAgain() { mThrowMax.Val = IO_Settings.mSet.lPlayerData.mThrowSpd; mThrowState = PC_THROW_STATE.SNOT_THROWING; }