- Home /
trying to get a good wall jump for my 2d game
I am new to programming who was to know wall jumping could be so hard lol.
What i need is when my player jumps on a certain wall, he jumps from side to side with added force like a dash or something and can only jump left to right or vise versa. I also need him to slide down the wall when jump button is not pressed.
Probably a annoying question but you got to start somewhere. Has any one got an idea how i can achieve this?
Any help would be great as i am not to sure how i can do this. P.s im new so if my code bad dont judge me haha.
Answer by mlnczk · Jan 14, 2019 at 02:18 PM
Ok so there is few things you can upgrade and think about to achieve what you want. Im not gonna do everything for you since it wont teach you much but I can give you ideas to solve your problem. First and foremost you are using Update method. This isnt correct. Whenever you touch rigidbody behaviour it has to be in FixedUpdate method it has better frequency calculations when it comes to physics. If you want your character to slowly slide down the wall whenever player dont jump but touches the wall you can consider changing player's rigidbody's gravityscale. Eg below: private void OnCollisionEnter2D(Collider2D collision){ if(collision.CompareTag("Wall")){ rb.gravityScale = -10f; //have fun changing value and adapting to your needs } }
private void OnCollisionExit2D(Collider2D collision){
if(collision.CompareTag("Wall")){
rb.gravityScale = 1; // should be default value
}
}
About jumping. Google and look for Spline Tools. You can find really nice spline assets completly for free. They allow you to move objects following lines. You can curve them do whatever you want and its pretty simple. You can Set on both sides on top of wall empty colliders and check if player's collider is InTrigger with one of those - right or left and then allow player to press second jump action to do the jump. If player leaves the trigger collider he cant jump anymore. When it comes to jump method itself. Spline should do the job. Just make player move following spline curved above wall tip until it lends at the end of it on the other side. You can also consider just simple animation and just play animation but it might be buggy and for sure less optimised. Anyways good luck!
Follow this Question
Related Questions
Why isn't my player looking the other direction when I wall jump (please help I am desperate) 1 Answer
How to fix the vibration while colliding and the suspension after jumping? 0 Answers
when attempting to jump my player shoots into the air and disappears. can someone help? 0 Answers
Unity 2D: Variable Jump Height with a Double Jump 0 Answers
How to implement a jump in 2D unity like in Mario and Luigi Superstar Saga? 0 Answers