Advertisement
TermSpar

Unity Player Movement

Nov 21st, 2015
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerMovement : MonoBehaviour {
  5.     public float moveSpeed;
  6.     private float maxSpeed = 5f;
  7.  
  8.     private Vector3 input;
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.    
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void Update () {
  17.         input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxis ("Vertical"));
  18.         if(rigidbody.velocity.magnitude < maxSpeed)
  19.         {
  20.             rigidbody.AddForce (input * moveSpeed);
  21.         }
  22.  
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement