CharacterBody2D walking on another CharacterBody2D

I am making an online 2D platformer, I had an issue where, if player 1 is underneath player 2 (or vice versa) and player 1 moves to the left or right, player 2 is sent flying to the opposite side.
I couldn’t find any forum post or any help whatsoever about this issue so I fixed it myself. Here’s how:
In the inspector I put the platform_on_leave to “Do Nothing”, this toned down the launch but it still launched the player to the opposite direction, just not far off.
Then I messed around and figured out that disabling the Floor Layer that matches my character collision layer fixed it completely.

What happens now, when player 1 steps on player 2, player 2 can freely move left and right, letting player 1 slide off of his head. I don’t know how to make player 1 stay on player 2’s head tho.
If you have any tips on how to make player 1 stay on player 2’s head while player 2 is moving I would appreciate it.
Have a nice day!

Do you need to do some scripting to compare the x position and y positions?

An area2D on each characters head might be easier - with an if to check that it’s the other player?

I can add some script I just have to understand the logic first. If I add an area2D like you said and detect the player what would I do afterwards? Can I access a player’s movement from another player? Idk how to approach it

Sometimes defining the actual logic is hard.

If you can write what you want in English (if that’s your first language) in the code as comments you can than convert that in to code as you figure out how things work.

You can definitely access variables from another scene, or use a global variable to hand things around.

Here’s part of my code to see if the player touches a coin in my platform game:

func _on_body_entered(body):
	if == ("player"):

You would probably use player1 and player2 instead of player…

nice! This is helpful for checking collision between players thanks, there probably is a better body parameter to check cause ‘name’ changes in my game depending on player input, I’ll work that one out on myself, thanks
Hopefully I will be able to move a player from another player, sounds weird but it has to be a thing

1 Like

I’m sure you’ll be setting the name as a variable to make sure that it won’t affect the coding.

The is the node/scene name - I don’t think the player will be able to change that, and if they did the game will have trouble sending signals between nodes/scenes.

In one of my games (the 2D RPG) the is “arstronaut” :laughing:

It’s not weird - once you figure out the maths/physics to handle your design you’ll be able to start putting the code in place.

Sometimes defining the physics in detail is the hardest part! :slight_smile:

I already did it! so I have this Area2D ‘hat’ on my player that detects anyone on his head. If player 2 is on top of player 1 I let player 1 access and change player 2’s position when player 1 moves (so player 1 takes the Area2D global_position) It was a nice idea with the area 2d thanks!

1 Like