/** * \brief Adds a callback function to the HP component, so that * the camera shakes when the player's HP reaches zero. * \param void * \return void */ private void Start() { GetComponent <HP>().AddDeathCallback(() => { float angle = Random.Range(-180, 179); float magnitude = Random.Range(minShake, maxShake); cam.Rotate(TrigPhysics.GetVelocity(angle, magnitude)); }); }
/** * \brief Fires bullets. * \param void * \return void */ void Fire() { if (Time.timeScale != 0.0f) { GameObject bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; bullet.transform.rotation = transform.rotation; bullet.GetComponentInParent <SphereTraveller>().Rotation = st.Rotation; Inertia inertia = bullet.GetComponentInParent <Inertia>(); // get standard velocity float stdSpeed = bullet.GetComponentInParent <SphereTraveller>().speed; float stdAngle = turretTransform.localRotation.eulerAngles.y; inertia.StdVelocity = TrigPhysics.GetVelocity(stdAngle + Random.Range(-spread, spread), stdSpeed); // get inherited velocity inertia.InheritedVelocity = st.LastDirection; // get angle inertia.Angle = stdAngle; } }
/** * \brief Sways the camera a little bit when the player moves. * \param void * \return void */ private void LateUpdate() { if (xAxis) { float target = Input.GetAxisRaw("Horizontal") * xRange; float delta = ((TrigPhysics.SignedRoll(target - transform.localEulerAngles.y) * speedDivisor)); if ((delta < -tolerance) | (delta > tolerance)) { transform.Rotate(new Vector3(0, delta * Time.deltaTime, 0)); } } if (yAxis) { float target = -Input.GetAxisRaw("Vertical") * yRange; float delta = ((TrigPhysics.SignedRoll(target - transform.localEulerAngles.x) * speedDivisor)); if ((delta < -tolerance) | (delta > tolerance)) { transform.Rotate(new Vector3(delta * Time.deltaTime, 0, 0)); } } }