I’ve recently started getting into game development with Unity 5 and C#. I’ve been looking into different things in an attempt to get something made. Right now I’m working on an over head game and currently my character moves up, down, left, right. I decided that I would like him to rotate to the left and right instead of simply moving side to side and then move forward in the direction he is facing.
This is my code for character movement right now:
using UnityEngine;
using System.Collections;
public class Player_Movement : MonoBehaviour {
Rigidbody2D rbody;
Animator anim;
// Use this for initialization
void Start () {
rbody = GetComponent ();
anim = GetComponent ();
}
// 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);
}
}
I’ve looked into how to do what I would like but have run into confusion. So could someone please help me and explain how to do it.