Hello all!
I have been experimenting with 2D top down game development for the last few months. Long story short I used to dabble in animations in Actionscript 3, but I have found unity to an extremely nice development tool. So I have decided to switch to unity.
I have not found too many zelda NES top down like game examples.
So far collisions are working great, my character will not leave the sandbox I have set up. Also the up, down, left and right animations are running fine during movement. Although sometimes the character will get stuck in an animation cycle for a couple seconds and stop.
First question is, does anyone know of any resources or helpful assets to learn the basic mechanics of 2d top down games?
Second the thing I am stuck on is how to keep the sprite from going crazy on multi buttons pressed like diagonal movements.
Thanks for taking the time to read this, I really hope to open a dialog ad learn some interesting things.
Also here is my current script for my character controls. If you have any criticisms I would be willing to hear them
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed = 1f;
private Animator animator;
private Rigidbody2D cachedRigidBody2D;
//private Transform cachedTransform;
// Use this for initialization
void Start () {
//cached animator
this.animator = this.GetComponent<Animator>();
//cached rigidbody
this.cachedRigidBody2D = this.GetComponent<Rigidbody2D>();
//this.cachedTransform = this.gameObject.transform;
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKey (KeyCode.D)) {
transform.position += new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
animator.Play("WalkingRight");
}
if(Input.GetKeyUp(KeyCode.D)) {
animator.Play("StandingRight");
}
if (Input.GetKey (KeyCode.A)) {
transform.position -= new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);
animator.Play("WalkingLeft");
}
if(Input.GetKeyUp(KeyCode.A)) {
animator.Play("StandingLeft");
}
if (Input.GetKey (KeyCode.W)) {
transform.position += new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);
animator.Play("WalkingUp");
}
if(Input.GetKeyUp(KeyCode.W)) {
animator.Play("StandingUp");
}
if (Input.GetKey (KeyCode.S)) {
transform.position -= new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);
animator.Play("WalkingDown");
}
if(Input.GetKeyUp(KeyCode.S)) {
animator.Play("StandingDown");
}
}
}
The only resources I would give you is the one’s that I would google. So I’m no help there, but, I see the issue with your code.
You need to divide your conditions into logical actions. Right now, in one frame, you could potentially hit all your keys at once and start all animations. You need some else ifs or elses to separate your logical flow, so only one animation can occur at a given frame/time.
Thanks for the reply! I will try that out and report my findings
I have tried google. It’s mostly Platforming 2d. If it is top down, its for touch controls for mobile.
I figured I would just dive right in and become apart of the unity community and hopefully someday post a basics guide
on top of what Sickwitit said about the directions, I’ve found when I programmed my own engine a while ago that sometimes it helps if you specify the you only want a certain key to be pressed, i.e. if inputkey = d and not s, I’m not sure the best way to do that the way you’ve written your code but the idea is pretty simple. This helped me get around bugs where the engine would make the character run twice as fast because they were receiving two movement inputs at the same time.