Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Update() {
- /* calculate rigidbody movement */
- movement = new Vector3( Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
- /* calculate mouse look to rotate the rigidbody*/
- mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
- mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
- smoothV.x = Mathf.Lerp(smoothV.x, mouseDelta.x, 1f / smoothing);
- smoothV.y = Mathf.Lerp(smoothV.y, mouseDelta.y, 1f / smoothing);
- mouseLook += smoothV;
- }
- void FixedUpdate() {
- /* apply rigidbody movement from Update() */
- transform.Translate( movement * moveSpeed * Time.deltaTime );
- /* apply rigidbody rotation from Update() */
- transform.localRotation = Quaternion.AngleAxis(mouseLook.x, transform.up);
- /* apply camera rotation from Update() */
- Camera.main.transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
- }
- rigidbody.MovePosition(movement * speed * Time.deltaTime)
- void FixedUpdate() {
- /* move the rigidbody */
- rigidbody.MovePosition(movement * moveSpeed * Time.deltaTime);
- /* rotate the camera */
- camera.transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
- /* but how can i rotate the rigidbody based on the cameras rotation??? */
- rigidbody.MoveRotation(?????);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement