I want to improve it, becouse my Player doesnt move smoothly. I wish he could move diagonally. Can you help me please?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
public float moveSpeed;
public float jumpHeight;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.W))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, moveSpeed);
}
if(Input.GetKeyUp(KeyCode.W))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(0,0);
}
if (Input.GetKeyDown(KeyCode.D))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
if(Input.GetKeyUp(KeyCode.D))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(0,0);
}
if (Input.GetKeyDown(KeyCode.A))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
if(Input.GetKeyUp(KeyCode.A))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(0,0);
}
if (Input.GetKeyDown(KeyCode.S))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x,-moveSpeed);
}
if(Input.GetKeyUp(KeyCode.S))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(0,0);
}
}
}