Skip to content

Instantly share code, notes, and snippets.

@chillax
Created January 30, 2013 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chillax/4673765 to your computer and use it in GitHub Desktop.
Save chillax/4673765 to your computer and use it in GitHub Desktop.
/*
* playermovement.js
*/
#pragma strict
public var speed:float = 1.0;
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
var moveDirection = Vector3(Input.GetAxis('Horizontal'), 0, Input.GetAxis('Vertical'));
moveDirection = Camera.main.transform.TransformDirection(moveDirection);
controller.SimpleMove(speed * moveDirection);
// http://answers.unity3d.com/questions/197589/only-look-at-the-movedirection-of-z-axis.html
var tempDirection = moveDirection;
tempDirection.y = 0;
transform.LookAt(transform.position + moveDirection);
Camera.main.transform.LookAt(transform);
}
@script RequireComponent(CharacterController)
/*
* projectile.js
*/
#pragma strict
var projectile:Rigidbody;
private var projectiles = new Array();
function Update () {
if (Input.GetButtonDown("Fire1")) {
var projectileClone:Rigidbody;
projectileClone = Instantiate(projectile, transform.position, transform.rotation);
projectileClone.velocity = transform.forward * 100.00;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment