2D Top down player won't move down
Here is the script I'm using I don't know why but he will not move down ... Up,Left and Right are no issue but down is apparently impossible I even tried (-Vector2.up * speed) still won't move down ... any help ??
using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour { public float speed;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector2.right * speed);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector2.left * speed);
}
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector2.up * speed);
if (Input.GetKey(KeyCode.S))
{
transform.Translate(Vector2.down * speed);
}
}
}
}
Also I'd recommend using Physics2D or Rigidbody2D for your movement later on. Trust me, it'll serve you much better in the future. You're smart, I'm sure you're able to figure out how to use it.
Answer by antiquote · Jun 17, 2016 at 08:02 PM
It seems you boxed in your down IF Statement with your up. Delete your second to last curly brace and move it up after your transform.Translate( Vector2.up * speed );
Answer by L2P_SouL · Jun 17, 2016 at 08:10 PM
Hahaha omg what a fail that was exactly what I did ahahaha thanks so much and I will keep that in mind ... still learning how to properly script so that should help thanks a bunch!!
It is my pleasure. I've been in your position before and I know how it is. Although, please use the "Add Comment" button if you wish to comment. Thank you.