Dear You-who-read-this-message,
Hello and thank you for taking the time to read through this post.
I am all new to Unity and to the world of game-making in general, but anyway I’ve wanted to make a simple 2D top-down style of game to add for my application to University (I want to study Game Arts, as I love creating arts and playing games), but as I am a total newbie, I am really struggling with the coding.
As mentioned above, I really want to keep things as simple as possible: all I want to make is a simple level with my character walking through the scene by the control of the arrow keys, and I have placed some objects like tables and chairs in the scene, so of course I also want him to stop at this objects (and not just run right through them). I believe I can achieve this effect by the implement of RigidBody and Collision Boxes, but I am still at the beginning of creating my scene, and it is the Character Controller I face the biggest troubles recently.
I have succeeded in controlling my character as so far that he will face the direction (North,East,South or West) when I press the equal direction on the keyboard (controlling him with the arrow keys), but he is only facing that direction, he is not really moving, and that is what I want to achieve; I want him to walk in the direction I press on the keyboard!
I have searched for appliable scripts and tutorials on the internet, but didn’t have much success so far; most times I would find scripts/tutorials for 2D platformers or for games that are controlled with the mouse, so if there is anybody out there who knows about a script I might use for my Character Controller or has heared about any good tutorial on 2D top down games controlled with the arrow keys, I would more than appreciate your help.
Please also find my CharacterController Script at the end of this message.
Waiting eagerly for your responses and thank you very much already in advance for your support,
sincerely yours, CLOE
using UnityEngine;
using System.Collections;
public class playerController : MonoBehaviour
{
public float speed;
private Animator animator;
// Use this for initialization
void Start()
{
animator = this.GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
var vertical = Input.GetAxis("Vertical");
var horizontal = Input.GetAxis("Horizontal");
if (horizontal > 0)
{
animator.SetInteger("Direction", 2);
}
else if (horizontal < 0)
{
animator.SetInteger("Direction", 0);
}
else if (vertical > 0)
{
animator.SetInteger("Direction", 1);
}
else if (vertical < 0)
{
animator.SetInteger("Direction", 3);
}
}
}