Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MoveScript : MonoBehaviour {
- public float turnSpeed = 80.0f;
- public float forwardSpeed = 15.0f;
- public float maxSpeed = 80.0f;
- private Rigidbody rb;
- void Start ()
- {
- rb = GetComponent<Rigidbody>();
- }
- void FixedUpdate ()
- {
- float turnFactor = Input.GetAxis ("Horizontal");
- Vector3 moveDirection = new Vector3 (turnSpeed*turnFactor, 0.0f, 1.0f*forwardSpeed);
- rb.AddForce (moveDirection);
- //Limit speed
- if(rb.velocity.magnitude > maxSpeed)
- {
- rb.velocity = rb.velocity.normalized * maxSpeed;
- }
- Debug.Log (rb.velocity.magnitude);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement