Stick to moving walls

Godot Version

4.2.1 stable

Question

Sorry, I’m afraid I have posted a very similar question to this one before but still haven’t found a solution.

The problem is trying to climb walls that are moving. My current climb mechanic only works on static bodies that do not move because there is no logic which actually “sticks” the character to a wall rather it just moves them up or down depending on player inputs.

This is the code that controls moving up and down, which runs on delta while in the climb state, (climb state is entered because of raycasts located on both sides of the character).:

	if Player.movement_input.y == 0:
		Player.velocity.y = lerp(Player.velocity.y, 0.0, 0.2)
	elif Player.movement_input.y < 0:
		Player.velocity.y = lerp(Player.velocity.y, -climb_speed, 0.2)
	elif Player.movement_input.y > 0:
			Player.velocity.y = lerp(Player.velocity.y, slide_speed, 0.2)

I was thinking as a possible solution, I could add a Marker2D as child to whatever moving wall the player climbs onto. The marker position would be restricted to move only around the perimeter of the shape and it would be affected by player input, (move up or down). So instead of the inputs directly affecting the character, they will move the marker, which in turn will be used by the player to move to that position.
Although I’m not sure this is a good idea, or that I even have the faintest idea on how to start, but I will start trying to code it today. lol

If anyone knows how to do it or if you think you have a better idea I would love to hear what you have to say. Thank you all.

Did you enable any moving platform wall layers for your character body?

1 Like

Just simply use the build-in property for moving objects, just change the character2d from grounded to floating, it will simple make it stick to moving/floating objects:

1 Like

It seems I have left all of those wall layers blank. But I don’t understand how I could use that to snap the player to the wall. I’m using raycasts currently to tell whether I should climb or not since I heard from a few places using the built in if_on_wall check can be inaccurate at times.

just make sure that the platform that is moving is a character2d and is set to floating.

1 Like

I have not thought of this before, let me try it real quick.

is_on_wall does require touching the wall, using a Moving Platform layers should move the player with a touching wall, not sure if it does snapping. Set the wall layer to match your wall’s collision layer, or fill in all of them like the floor layers might.

Motion mode “Floating” will ignore moving platforms in any direction.

1 Like

Alright so I made a rectangle platform that is a characterbody2D, it is on floating motion mode, and it moves up and down continuously. Now when the player goes to climb it switches to floating mode as well but it doesn’t stick the player to the characterbody platform. I may have read your reply wrong, let me know if I misunderstood.

Noo, the player stays in grounded mode it never changes, just set the moving platform to floating.

1 Like

This works pretty well, all I had to do was set the wall layers as you suggested, although I’m not entirely sure its working as the character will move rapidly if the wall is sloped, but I believe this is a bug that has something to do with the entering the climb state.
Otherwise if the wall is flat, the character moves along with it fine.

But one thing I dont understand how it works because as the property says on the characterbody2d node, the velocity will be added after leaving the platform, so I’m just confused as to how it works since I’m constantly on the wall but it moves along with it still.

It’s part of the CharacterBody2D implementation, Grounded mode has a lot of checks for different behaviour on floors, walls, and ceilings. It has customizable behaviour when leaving the platform, like if your character jumps off the moving wall should they gain the velocity of the wall too? Depends on how you programmed your character controller a little. With a wall layer selected it will stick to the walls (as best it can)

1 Like

So this might be out of scope for my original question but your solution seems to work but when my character approaches a moving wall which happens to be slanted, the character will be instantly moved to the top of the platform, and even if I try to walk along the top of the slanted platform, it instantly moves the character to the higher point on the slope.
I tried changing some settings on characterbody like the block_on_wall, add_velocity from moving platforms, wall layers but I’m not sure at all whats going on. As far as I know, I have no “stepping” mechanics implemented or anything like that unless there is something there by default?

I tried your suggestion by making a square characterbody, set to floating mode, that moves along a path, back and forth. I try to climb on the side of it with my character which is set to grounded mode but the velocity is not added, sorry Im not sure what to do.

maybe the step up is caused by a high velocity towards the slope with move_on_slide? There is a wall slide angle, maybe that should be reduced?

1 Like

debug
I changed the min slide angle to many values but still the behavior persists, but it has some nuances I found after further testing.
I made this diagram which might be terrible but I will try lol, I might make another post all together with more information if anything,

So the grey rectangle is the moving platform and it goes up and down.

Now let’s start with the player on top of the diagram.
If he falls down on the platform from there, he will be instantly moved to point “C”. If you hit the bottom of the platform you will be instantly moved the point opposite to “C”.

Now for the player on the right.
If he hits the platform from trajectory “A”, he will be instantly moved to point “C”.
If he hits the platform from trajectory “B”, he will just bounce off.
The only difference from trajectory “A” and “B” is that you have to hit it from above or below the midpoint of the side face.
If you approach the left face of the platform then the results are the same as hitting it from the right side except reversed, so hitting the bottom half of the left side will rapidly move the player towards the bottom point of the rectangle, and hitting the top half on the left side will allow you to bounce off.

Making the slide angle higher allows the player to walk on the portion of the platform where you would normally bounce off but thats it, the quick movement of the player still persists.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.