- Home /
2d platformer dash move.
So, i am doing a 2d platformer project, and i have a bit of a problem. I want the player to move, but haven't found a good way to do it with the dash move working. I know i could use transform.translate but the player always glitches into the walls a little bit.
if(movable){ //Moves //What do i put here so it will work? }
dashTimer += Time.deltaTime;
if(Mathf.Round(Input.GetAxisRaw("Horizontal")) != 0 && dashTimer > dashTime && Input.GetKeyDown("x")){
//Dashes the player forward and resets the timer
direction = Mathf.Round(Input.GetAxisRaw("Horizontal"));
rb.velocity = new Vector2(0, rb.velocity.y);
rb.AddForce(Vector2.right * direction * dashForce , ForceMode2D.Impulse);
dashTimer = 0;
}
Hi @Lenny991,
Sorry for the previous answer, I had the wrong discussion.
Is the problem with your player not moving well horizontally, or is he getting stuck in walls?
Answer by Devster2020 · Jul 06, 2021 at 09:50 AM
If you want to get a correct dash, without the momentary influence of gravity and speed, you need to set the speed to 0 for that period of time.
So instead of doing this
rb.velocity = new Vector2(0, rb.velocity.y);
Do this
rb.velocity = Vector2.zero;
it works fine otherwise but the movement that i use is rb.velocity = new Vector2((something), 0); so that it stops the dash from happening at all
Your answer
Follow this Question
Related Questions
2D player keeps getting dragged to the left for some reason. 0 Answers
Player movement script for a stickman 1 Answer
2D How to make character slowly stop after moving 1 Answer
How do i make a cube move (Continuosly without stopping) when i press a button once in unity 2D 2 Answers
Why do I double jump? This isn't supposed to happen... 2 Answers