//TODO: 3) orient the camera pointing to the plate's normal // 4) turn on the arrow pointers // 5) turn on mouse controls // 6) limit range of camera movement (might require a new superball state) void OnCollisionEnter(Collision collision) { print(collision.gameObject.name); //"Sphere" ballPosition = collision.gameObject.transform.position; //Debug.DrawRay(ballPosition, collision.contacts[0].normal * -5f, Color.cyan, 480f); ballVelocity = collision.gameObject.GetComponent <Rigidbody>().velocity; HaltSuperballMovement(); PositionAndOrientCamera(collision); arrowsBehavior.AlignArrowsForAiming(ballPosition, startingRotation * Quaternion.AngleAxis(90, Vector3.right)); reaimingActive = true; sbBehavior.ballState = SuperballBehavior.SuperBallState.REAIMING; }
//https://forum.unity.com/threads/simple-first-person-camera-script.417611/ //taken from the website above // Works in the REAIMING state and the ATREST state void UpdateAim() { rotAverageY = 0f; rotAverageX = 0f; rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotationX += Input.GetAxis("Mouse X") * sensitivityX; rotArrayY.Add(rotationY); rotArrayX.Add(rotationX); if (rotArrayY.Count >= frameCounter) { rotArrayY.RemoveAt(0); } if (rotArrayX.Count >= frameCounter) { rotArrayX.RemoveAt(0); } for (int j = 0; j < rotArrayY.Count; j++) { rotAverageY += rotArrayY[j]; } for (int i = 0; i < rotArrayX.Count; i++) { rotAverageX += rotArrayX[i]; } rotAverageY /= rotArrayY.Count; rotAverageX /= rotArrayX.Count; rotAverageY = ClampAngle(rotAverageY, minimumY, maximumY); rotAverageX = ClampAngle(rotAverageX, minimumX, maximumX); Quaternion yQuaternion = Quaternion.AngleAxis(rotAverageY, Vector3.forward); Quaternion xQuaternion = Quaternion.AngleAxis(rotAverageX, Vector3.up); transform.localRotation = originalRotation * xQuaternion * yQuaternion; arrowsBehavior.AlignArrowsForAiming( sphereCollider.transform.position, CannonBarrel.transform.rotation); }