Last active
March 21, 2018 21:46
-
-
Save pkarjala/459838e2a0a8daf2625daadb2cb9e253 to your computer and use it in GitHub Desktop.
Physics Script for Roller Ball
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
// Derived from https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/moving-player?playlist=17141 | |
// Additional comments and renaming of some variables for clarity by Patrick Karjala | |
public class PlayerController : MonoBehaviour { | |
// The speed that the object will move at; defaults to 0. | |
public float speed; | |
// The Rigidbody of the object we’re manipulating; defaults to THIS object. | |
private Rigidbody myRigidBody; | |
void Start () | |
{ | |
myRigidBody = GetComponent<Rigidbody>(); | |
} | |
void FixedUpdate () | |
{ | |
float moveHorizontal = Input.GetAxis ("Horizontal"); | |
float moveVertical = Input.GetAxis ("Vertical"); | |
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); | |
myRigidBody.AddForce (movement * speed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment