playMaker

Author Topic: Wall jump 2D  (Read 1204 times)

ffffffffff

  • Playmaker Newbie
  • *
  • Posts: 18
Wall jump 2D
« on: April 26, 2020, 12:49:46 AM »
How to make wall jump.which action should i use. Pls help. It will be useful if you have picture of it

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 175
Re: Wall jump 2D
« Reply #1 on: April 26, 2020, 08:41:33 PM »
Heya,

There are many ways to do this but the solution you build always depends on the way your 2D character is controlled.

Your main concern is gravity; do you use Unity's gravity or do you create your own system. I personally chose to create my own system so I have complete control over it. Since my game has no slopes on the ground I don't have the need to have a constant downward force applies when the character is standing or running.

The key feature to this system is raycasting. You basically want to be raycasting in every direction your character can move (in a 2D game that's left, right, up and down).

Take a look at the screenshot I've attached, it's a wireframe of my 2D character controller in action. You can see the green capsule collider and a bunch of lines that represent the rays I create to detect the environment. I have 3 rays for the horizontal movement. For efficiency, I only cast horizontal rays in the direction the player is facing or moving. In this case they are cast to the left. I have 3 rays always being cast down (these are for detecting when the player falls of a ledge or when the player hits the ground after a jump). Lastly, I have 2 rays casting up to detect when the players head hits the ceiling.

Since I have no gravity in my solution I apply my own Y velocity force (either jumping or falling) with a curve (I use the CURVE FLOAT action).

Now if my character is jumping I use the horizontal rays to detect if the player has hit a wall. When this happens I set the velocity to a constant value that's lower than the fall speed to simulate the player slowly sliding down the wall.

I won't go into specific detail of how I built this controller but I will say that I use 2 FSM's on my player that share values with each other to make it all work:
  • Rascast/Move FSM: This controls the raycasting and the player movement.
  • Navigation FSM: This processes user input and deals with the movement logic (if the player is jumping, falling, wall sliding, etc).

I hope this helps you to get started. If you are a beginner then you might find this is a pretty advanced thing to do, but don't let that stop you! This can be a great challenge for you!

The main actions you want to be using are Ray Cast 2D, Set Velocity 2D and Curve Float. I've attached a screenshot of my Navigation FSM. It's a bit more complicated than what you will need since my game is an auto-runner of sorts where the player is constantly running and changes direction automatically if they hit a wall (like the great mobile game Leap Day).

Hope this helps! Let me know if you have any questions.

Cheers,

Simon


hoyoyo80

  • Full Member
  • ***
  • Posts: 136
Re: Wall jump 2D
« Reply #2 on: April 26, 2020, 09:42:44 PM »
So now ur character jump already?

if so i try to help by pseudocode:
1.Create a trigger mesh(a box) that will detect "wall" and attach it to ur character and ensure it flip together with ur character
2.When jumping, trigger event to check whether the trigger in 1 collide with a wall
3.if 2 is true, change state to check whether u press another jump button
4. if 3 is true, flip character and make another jump