Advertisement
Guest User

code

a guest
Aug 1st, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1.  
  2. using UnityEngine;
  3. using System.Collections;
  4.  
  5. public class MoveScript : MonoBehaviour {
  6. public float turnSpeed = 80.0f;
  7. public float forwardSpeed = 15.0f;
  8. public float maxSpeed = 80.0f;
  9.  
  10. private Rigidbody rb;
  11.  
  12.  
  13. void Start ()
  14. {
  15. rb = GetComponent<Rigidbody>();
  16.  
  17. }
  18.  
  19. void FixedUpdate ()
  20. {
  21.  
  22.  
  23. float turnFactor = Input.GetAxis ("Horizontal");
  24.  
  25.  
  26. Vector3 moveDirection = new Vector3 (turnSpeed*turnFactor, 0.0f, 1.0f*forwardSpeed);
  27.  
  28.  
  29.  
  30. rb.AddForce (moveDirection);
  31.  
  32.  
  33.  
  34. //Limit speed
  35. if(rb.velocity.magnitude > maxSpeed)
  36. {
  37. rb.velocity = rb.velocity.normalized * maxSpeed;
  38. }
  39. Debug.Log (rb.velocity.magnitude);
  40.  
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement