when the Player presses a key, this code is called:
rb.velocity += new Vector2(0, probs.speed);
this makes the player move up, no matter if the player is rotated to the front.
how can i make the player move to his front?
Like this:
rb.AddRelativeForce(Vector2.up * probs.speed, ForceMode2D.Impulse);
Change Vector2.up to .down, .left, .right depending on where zero rotation starts.
Note that if you do this per-frame and don’t scale the change by time then you’ll get a frame-rate or fixed-update dependant acceleration which is something you probably don’t want. Scaling your speed by the elapsed time (Time.deltaTime or Time.fixedDeltaTime) will solve that.
1 Like