How do I assign a velocity to an object on only 1 axis?
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?
Answer by Wereb · Feb 01, 2021 at 06:18 PM
Should've also mentioned I'm new to Unity and C#, probably a stupid mistake or something
Your answer
Follow this Question
Related Questions
WheelJoint2D rotates parent object 1 Answer
How to move character with UI buttons? 0 Answers
2D Accuracy 0 Answers
Player controlled platforms 0 Answers
Getting rid of 2D collision jitter 1 Answer