void FixedUpdate() { var PlayerIsMoving = rb.velocity.magnitude > thresholdSpeed; // Used to limit when player can rotate var ValidBreathDetected = UserInput.isExhaling(); var UserIsPressingButton = UserInput.isHoldingButtonDown(); if (PlayerIsMoving) { pc.showAsInactive(); pc.stopRotating(); cc.UpdateDirection(); } else { pc.showAsActive(); if (UserIsPressingButton) { pc.Rotate(); direction = pc.getDirection(); } else { pc.stopRotating(); cc.UpdateDirection(); } } if (ValidBreathDetected) // Move player { var convertedDirection = direction * (float)Math.PI / 180; var forceDirection = new Vector3(speed * (float)Math.Sin(convertedDirection), 0.0f, speed * (float)Math.Cos(convertedDirection)); rb.AddForce(forceDirection * speed); } }
public void UpdateDirection() { // Rotate the camera to always look at player, and position it at constant distance (offset) var convertedDirection = pc.getDirection() * (float)Math.PI / 180; transform.rotation = Quaternion.LookRotation(new Vector3((float)Math.Sin(convertedDirection), -1f, (float)Math.Cos(convertedDirection))); transform.position = player.transform.position + new Vector3(offset.z * (float)Math.Sin(convertedDirection), offset.y, offset.z * (float)Math.Cos(convertedDirection)); // yay maths }