It gives me an error when I type in rb.velocity.x or y and try to assign it a single variable, it only allows me to make it a rb.velocity Vector2, I’ve read that it is just the way it is. But I have a problem:
private void FixedUpdate()
{
rb.velocity = new Vector2(direction * movementSpeed, rb.velocity.y);
if (Input.GetButtonDown("Jump"))
{
rb.AddForce(new Vector2(rb.velocity.x, jumpForce), ForceMode2D.Impulse);
}
}
First I make a constantly updating function that sets my x axis movement velocity, then another for jumping (y axis). But since both of those arguments have to be of Vector2 type and not just x or y variables, on the Update function they override each other.
How can I stop the x velocity that shouldn’t even be there on jump function overriding the x I’m controlling and the same with the y axis?