HeroMobility.cs 575 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
using UnityEngine;
using System.Collections;

public class HeroMobility : MonoBehaviour {
	public float playerSpeed = 1f;
	private Rigidbody2D playerRB;
	Animator anim;

	void Start () {
		playerRB = GetComponent<Rigidbody2D> ();
		anim = GetComponent<Animator> ();
	}
Joshua DeRossett's avatar
Joshua DeRossett committed
13 14

	void FixedUpdate () {
15 16 17 18 19 20 21 22 23
		Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
		playerMove (input);
	}

	void playerMove (Vector2 input){
		//Controls hero movement in all 8 directions
		playerRB.MovePosition((Vector2)transform.position + input*playerSpeed);
	}
}