Advertisement
Guest User

movement

a guest
Nov 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Movement_1 : MonoBehaviour
  6. {
  7. public Transform player_camera, center_point;
  8.  
  9. KeyCode moveF;
  10. KeyCode moveB;
  11. KeyCode moveR;
  12. KeyCode moveL;
  13.  
  14. float zoom;
  15. float mouseX;
  16. float mouseY;
  17.  
  18. Vector3 moveFB;
  19. Vector3 moveRL;
  20.  
  21. public float acc, speed, max_speed;
  22.  
  23. Rigidbody rb;
  24.  
  25.  
  26. private void Start()
  27. {
  28. moveF = KeyCode.W;
  29. moveB = KeyCode.S;
  30. moveR = KeyCode.D;
  31. moveL = KeyCode.A;
  32.  
  33. zoom = -5f;
  34. player_camera.transform.position = new Vector3(0, 2, zoom);
  35.  
  36. mouseX = 0;
  37. mouseY = 0;
  38. moveFB = new Vector3(0, 0, acc);
  39. moveRL = new Vector3(acc, 0, 0);
  40.  
  41. rb = GetComponent<Rigidbody>();
  42. }
  43.  
  44. void FixedUpdate()
  45. {
  46. mouseX += Input.GetAxis("Mouse X");
  47. mouseY -= Input.GetAxis("Mouse Y");
  48.  
  49. mouseY = Mathf.Clamp(mouseY, 0f, 50f);
  50. center_point.localRotation = Quaternion.Euler(mouseY, 0, 0);
  51.  
  52.  
  53.  
  54. if (Input.GetKey(moveF))
  55. {
  56. if (rb.velocity.magnitude < speed)
  57. {
  58. rb.AddRelativeForce(Vector3.forward + moveFB);
  59. }
  60. }
  61. else if (Input.GetKey(moveB))
  62. {
  63. if (rb.velocity.magnitude < speed)
  64. {
  65. rb.AddRelativeForce(Vector3.forward - moveFB);
  66. }
  67. }
  68.  
  69. if (Input.GetKey(moveR))
  70. {
  71. if (rb.velocity.magnitude < speed)
  72. {
  73. rb.AddRelativeForce(Vector3.forward + moveRL);
  74. }
  75. }
  76. else if (Input.GetKey(moveL))
  77. {
  78. if (rb.velocity.magnitude < speed)
  79. {
  80. rb.AddRelativeForce(Vector3.forward - moveRL);
  81. }
  82. }
  83.  
  84. transform.localRotation = Quaternion.Euler(0, mouseX, 0);
  85. Debug.Log($"velocita' {rb.velocity.magnitude}");
  86.  
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement