Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. void Update() {
  2.  
  3. /* calculate rigidbody movement */
  4. movement = new Vector3( Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
  5.  
  6. /* calculate mouse look to rotate the rigidbody*/
  7. mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
  8. mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
  9. smoothV.x = Mathf.Lerp(smoothV.x, mouseDelta.x, 1f / smoothing);
  10. smoothV.y = Mathf.Lerp(smoothV.y, mouseDelta.y, 1f / smoothing);
  11. mouseLook += smoothV;
  12.  
  13. }
  14.  
  15. void FixedUpdate() {
  16.  
  17. /* apply rigidbody movement from Update() */
  18. transform.Translate( movement * moveSpeed * Time.deltaTime );
  19. /* apply rigidbody rotation from Update() */
  20. transform.localRotation = Quaternion.AngleAxis(mouseLook.x, transform.up);
  21. /* apply camera rotation from Update() */
  22. Camera.main.transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
  23.  
  24. }
  25.  
  26. rigidbody.MovePosition(movement * speed * Time.deltaTime)
  27.  
  28. void FixedUpdate() {
  29. /* move the rigidbody */
  30. rigidbody.MovePosition(movement * moveSpeed * Time.deltaTime);
  31. /* rotate the camera */
  32. camera.transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
  33.  
  34. /* but how can i rotate the rigidbody based on the cameras rotation??? */
  35. rigidbody.MoveRotation(?????);
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement