I’ve recently started getting into game development, I’m making a little simple 2d game. I’ve somewhat worked out character movement after some research but there is a change I would like to make. I just don’t know how.
using UnityEngine;
using System.Collections;
public class Player_Movement : MonoBehaviour {
Rigidbody2D rbody;
Animator anim;
// Use this for initialization
void Start () {
rbody = GetComponent<Rigidbody2D> ();
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
if (movement_vector != Vector2.zero) {
anim.SetBool("IsWalking", true);
anim.SetFloat("Input_X", movement_vector.x);
anim.SetFloat("Input_Y", movement_vector.y);
} else {
anim.SetBool("IsWalking", false);
}
rbody.MovePosition (rbody.position + movement_vector * Time.deltaTime);
}
}
Instead of the player simply moving left, right, up, down. I would like him to rotate left and right instead and than instead of simply moving up and down I want him to move in the direction he is facing. Could someone help me with this?