H
H
Haddle Haddle2021-04-10 16:02:03
Unity
Haddle Haddle, 2021-04-10 16:02:03

Why doesn't velocity work for right and left?

For example, I write this code:
_rb.velocity = Vector2.up * jumpForce;
And my character jumps up, obviously.
And I need it to sort of bounce off the enemy in the other direction, for example - the enemy hit from the right, I write this code

_rb.velocity = Vector2.left * knockbackForce;

или такой - 

_rb.velocity = new Vector2(knockbackForce, _rb.velocity.y);

I have 2 in these variables. (float)

It seems like they should be repelled. If you know how to solve it, write, but if you know how to make repulsion not through this method, I will also be grateful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-04-10
@Haddle

Why not read the documentation first? Where smart ideas have long been expressed.

The velocity vector of the rigidbody. It represents the rate of change of Rigidbody position.
In most cases you should not modify the velocity directly, as this can result in unrealistic behavior - use AddForce instead Do not set the velocity of an object every physics step, this will lead to unrealistic physics simulation. A typical usage is where you would change the velocity is when jumping in a first person shooter, because you want an immediate change in velocity.
Note: The velocity is a world-space property.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question