hi im new to coding and was just trying some stuff out and i made this code for wall jumping in 2d, it jumps upwards correctly but there is no movement on the x axis. so id like to know what im doing wrong.
move_and_slide()
var collision_pos = get_last_slide_collision()
if Input.is_action_just_pressed("ui_accept") and is_on_wall():
velocity.y = JUMP_VELOCITY
print(int(sprite_2d.global_position[0]))
print(collision_pos.get_position()[0])
if collision_pos.get_position()[0] > int(sprite_2d.global_position[0]):
$Timer.start()
velocity.x = -500
await $Timer.timeout
else:
$Timer.start()
velocity.x = 500
await $Timer.timeout
I would suggest not using the is_on_wall() function - because the user has to have a force acting on it to get onto the wall either by pressing the arrow key into the wall, and there are times when it just plain doesn’t work. I could never get the function to work by jumping to the wall.
I would show you what I used to solve this but my code is pretty horrible and hard to read and I have ladders and Ice parts and changing of animations all over the place. So, I really suggest watching this video which is what my solution was based on and will work 100% of the time:
I had another video which was useless using that stupid is_on_wall() function . This is much better and pretty simple idea. Mind you this video uses states which I didn’t use, so, depending of your understanding of coding you usage may vary. Even though this was made for Godot 3.4, I had no problems with 4.2.2, well, I lie I had problems with getting the animations correct, but, not the wall-jumping itself. I also ditched the idea of wall-sliding for wall-climbing.
move_and_slide is usually the last line in the physics process unless you are using is_on_wall() . Stupid function, another reason to get rid off it.
In any case I just realized that I do have my character code on the forum, so, if you want to knock yourself out, it is here:
Just realize there are a LOT of booleans being set and checked against so I know which item the character is on. It’s not the best code, but, it’s the best I can do for now.
i move the move_and_slide() after the code and the wall jump code comes after the left right movement
and it still doesnt work.
i also tried the get_wall_normal code and it does move on the x axis but not for very long and i cant seem to get the timer to work so it moves in the x axis for a certain amount of time
Yea, it works best if you jump push a direction into the wall. Let go of direction and jump. Then you should be able to just keep jumping if you have a walled area.
It definitely needs some tuning. I think you can start by removing air movement.
I was mainly trying to show you how to manage the x axis. Just be aware that you will override the character movement if you simply say velocity.x = direction * SPEED
But in the end you should probably disable direction movement after a wall jump for a small period of time.
Also don’t use await in a process function. Do something like this with a signal connection.
var movement_enabled : bool = true
...
# after wall jump
movement_enabled = false
Timer.start() # or restart timer if multiple wall jumps
...
Timer.timeout.connect(func (): movement_enabled = true )
Or better yet, get an animation tree with a state machine to do the timeout for you
That should return a true when you run into a wall made from tiles. Possibly a wall made from a sprite like I used can’t remember(???). In case you are wondering this is one frame of the wall_climbing animation. Notice the wallchecker is just one pixel wider than the sprite detection area yet shorter than the whole sprite to give the feeling of attachment to the wall.
Since the wallchecker is only facing to the right you will need to flip it in order to face to the left so in your direction code when you are going right you need to have: