HeroMobility.cs 850 Bytes
Newer Older
Zack Rembisz's avatar
Zack Rembisz committed
1 2 3 4 5 6 7
using UnityEngine;
using System.Collections;

public class HeroMobility : MonoBehaviour {
	public float playerSpeed = 1f;
	private Rigidbody2D playerRB;
	Animator anim;
8 9
    private Vector2 lastPos;
    public Vector2 deltaPos;
Zack Rembisz's avatar
Zack Rembisz committed
10 11 12 13 14

	// Use this for initialization
	void Start () {
		playerRB = GetComponent<Rigidbody2D> ();
		anim = GetComponent<Animator> ();
15 16
        lastPos = playerRB.position;
    }
Zack Rembisz's avatar
Zack Rembisz committed
17

18 19
    // Update is called once per frame
    void FixedUpdate () {
Zack Rembisz's avatar
Zack Rembisz committed
20 21 22 23 24 25 26 27 28
		Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
		playerMove (input);

	}


	void playerMove (Vector2 input){

		//Controls hero movement in all 8 directions
29 30 31
		playerRB.MovePosition((Vector2)transform.position + input.normalized*playerSpeed);
        deltaPos = playerRB.position - lastPos;
        lastPos = playerRB.position;
Zack Rembisz's avatar
Zack Rembisz committed
32

33
    }
Zack Rembisz's avatar
Zack Rembisz committed
34
}