- Home /
Question by
Aapakaaq · Aug 20, 2016 at 09:43 AM ·
2dgravityjumpplatformer
2D - Change jump direction
Greetings everyone.
I'm trying to create a 2D platformer, and I wish to change the jump direction, when the player has rotated. The rotation is working fine, but I cant make the player jump the x direction instead of the y direction.
Here is the code:
//Jump button
if (Input.GetKeyDown(KeyCode.Space) && grounded) {
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
}
Thanks for taking your time reading this.
Comment
Best Answer
Answer by Effervescence · Aug 21, 2016 at 06:19 AM
Jump the x direction? So like a dash?
Just switch the x and y values:
GetComponent<Rigidbody2D>().velocity = new Vector2(jumpHeight, GetComponent<Rigidbody2D>().velocity.y);
Your answer
Follow this Question
Related Questions
Make a 2D jump? 0 Answers
Network Client does not Groundcheck 0 Answers
Jump and run on a circle (2D) 0 Answers