// Changed from Update to FixedUpdate because dealing with physics. //Update is rendered every frame, want to use to get input events, then "record event with flag", and use //FixedUpdate to respond to the input. //If have lots of physics may want to leave fixed timestp at 1/50 or less and use interpolation to strain cpu less void Update() { //Getting touchpad input for movement if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { touchpadInput = device.GetAxis(); } else { touchpadInput = Vector2.zero; } //Getting trigger and grip input for gun control if (gunAttached) { if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { ballShooter.ShootBall(); RumbleController(0.012f, 800f); if (mgc.gamePhase == 0) { mgc.gamePhase = 1; } } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { ballShooter.ShootBall(); RumbleController(0.012f, 800f); } } }
private IEnumerator Start() { m_Reticle.Show(); m_Radial.Hide(); // In order, fade in the UI on how to use sliders, wait for the slider to be filled then fade out the UI. yield return(StartCoroutine(m_HowToUseFader.InteruptAndFadeIn())); yield return(StartCoroutine(m_HowToUseSlider.WaitForBarToFill())); yield return(StartCoroutine(m_HowToUseFader.InteruptAndFadeOut())); yield return(StartCoroutine(m_CameraMovement.GameStart())); //move camera to right position and start shooting the ball // In order, fade in the UI on confirming the use of sliders, wait for the slider to be filled, then fade out the UI. yield return(StartCoroutine(m_HowToUseConfirmFader.InteruptAndFadeIn())); while (true) { yield return(StartCoroutine(m_HowToUseConfirmSlider.WaitForBarToFill())); //yield return StartCoroutine(m_HowToUseConfirmFader.InteruptAndFadeOut()); yield return(StartCoroutine(m_BallShooter.ShootBall())); } //// Fade in the final UI. //yield return StartCoroutine (m_ReturnFader.InteruptAndFadeIn ()); }
IEnumerator ShootAtPlayer(Vector3 directionToShoot) { coroutineRunning = true; if (directionToShoot != transform.forward) { yield return(new WaitForSeconds(1)); Vector3 direction = playerHead.transform.position - transform.position; Debug.Log("distance is: " + direction.magnitude); float travelTime = direction.magnitude / ballShooter.initial_velocity; //(-1f * 0.003f / 0.5f) * Mathf.Log (1f - (direction.magnitude * 0.5f / (ballShooter.initial_velocity * 0.003f))); Debug.Log("traveltime is: " + travelTime); float drop = 4.9f * Mathf.Pow(travelTime, 2f); Debug.Log("drop is: " + drop); Vector3 targetPosition = playerHead.transform.position + Vector3.up * drop; transform.forward = (targetPosition - transform.position).normalized; //aim so that ball arcs properly } ballShooter.ShootBall(); yield return(new WaitForSeconds(1f / bps)); coroutineRunning = false; }