Skip to content

Instantly share code, notes, and snippets.

@pkarjala
Last active March 21, 2018 21:46
Show Gist options
  • Save pkarjala/459838e2a0a8daf2625daadb2cb9e253 to your computer and use it in GitHub Desktop.
Save pkarjala/459838e2a0a8daf2625daadb2cb9e253 to your computer and use it in GitHub Desktop.
Physics Script for Roller Ball
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