Need help moving on the Y axis in Unity 2d

So I was able to get movement on the x axis by using this code Rigidbody2D rb; public float spd; public float xaxis;

void Start() { rb = gameObject.GetComponent<Rigidbody2D>(); } void FixedUpdate() { //Movement xaxis = Input.GetAxisRaw("Horizontal") * spd; //Move with X = Left right Vector2 VelocityX = rb.velocity; VelocityX.x = xaxis; rb.velocity = VelocityX; //Max Movement spd if (rb.velocity.magnitude > spd) { rb.velocity *= spd / rb.velocity.magnitude; } } 

But I also need movement on the Y axis, but I am having trouble with that, whenever I copy the code for the xaxis to fit the Y axis, it results in slow falling, and if I hold down the Y button it continues moving up, help?

submitted by /u/PossibleOil
[link] [comments]

Leave a Reply