#Wall jump state "Flickering"(?

1 messages · Page 1 of 1 (latest)

jolly root
#

Ive been learning platformer movement stuff for the player character, including a wall jump. Issue is that after refactoring the code into a state machine i realized the player "flickers" between the ON_WALL and FALL states. this bothers me a lot as i had planned stuff exclusive to the wall slide (like shooting on the opposite side of the wall). Below is a video illustrating my problem and a txt with the state machine, as well as both the jump and wall jump functions, as i felt they were the most relevant but ill provide more code if needed

#

(oh the low framerate doesnt do it justice, just note that the fall state is 3 and the on_wall state is 7, and they flicker back and forth)

quick crater
#

You may already know this, but looking at this code:

PLAYER_STATE.FALL:
  ...
  if velocity.y > 0 and is_on_wall_only():
    current_state = PLAYER_STATE.ON_WALL

PLAYER_STATE.ON_WALL:
  ...
  if not is_on_wall_only():
    current_state = PLAYER_STATE.FALL

Without some manual testing or debugging it's hard to say exactly what's happening. But I'd bet that not is_on_wall_only(): isn't returning what you expect - though I can't say why.

I'd be curious if the is_on_wall_only() returns true in your handle_wall_jump()? Because after that you move_and_slide() and check is_on_wall_only() again. So if it returns true in your wall jump code and then returns false after move_and_slide that might be worth investigating?

(I'm also assuming all this code is already in _physics_process())

#

Oh actually, in your WALL state do you do anything to move the body into the wall itself? Because if you don't then it won't be moving towards the wall and therefore won't collide with it, which would result in is_on_wall_only() returning false.

jolly root
#

should i add a "not is_action_pressed" condition or something on the fall transition?

#

nope, that didnt work

#

so how do i make sure the body is moved to the wall?

quick crater
#

Well off the top of my head you've got a couple options. But I think the main thing you need to ask is: Do you need to detect if the player is on a wall during the WALL state?

Your current check suggests you are wanting to detect collision to confirm if they are on a wall every frame. But if you'd rather just assume they are on a wall during the wall state and detect the point when they are not on a wall, you could do that instead. Kinda depends on your goal.

#

Thought saying that out loud I don't have an exact answer for detecting when they slide down a wall and then should freefall they go past the end of the wall...

You could always just forcibly move the body into the wall by a tiny bit before calling move_and_slide. That feels a tiny bit hacky to me, but it really depends on your use case 😅

jolly root
#

How exactly do I move it though? I'm still very new at gd script, plus I don't know where I should "unstick" the player out of the wall after that

quick crater
jolly root
#

Yup! I forgot to mention it, now that I'm realizing.
I followed Heartbeast's Heart Platformer tutorial on YouTube and then put everything in a state machine following a tutorial on GDquest's website

quick crater
#

OK gotcha. I can walk you through some of it then, but you may want to review that tutorial if you're still not familiar with how to move objects around. I just don't have the context of the tutorial to explain things relative to that, but I can speak to things generally.

When you move a physics body around like this (I assume this is a CharacterBody2D), the body is affected by physics settings. Looking at the code you've shared, there are lots of related pieces such as modifying velocity direclty and handling some acceleration via handle_acceleration(). Then, when you call move_and_slide() it will take the various variables in play, apply them to the body (effectively applying physics), and move the body to the resulting location.

So if you wanted to move the body into the wall, you could just alter the velocity.x value to move towards the wall. Something like:

velocity.x += -0.00001 # Move the body left
# OR
velocity.x += 0.00001 # Move the body right
# THEN
move_and_slide()

So you'd have to track which side of the player the wall is on, and then modify the velocity accordingly before you call move_and_slide().

jolly root
#

that doesnt seem to be it, i tried both before move_and_slide and neither worked in their respective sides

#

wait ooooooh i forgot to add the handle accel