Is there any way to prevent two characterBody push each other when use move_and_slide?

Godot Version

Godot 4.3.beta2

Question

I’m newer to Godot Engine and found something weired to the part of 2d physic. Two CharacterBody2D can push each other when they both use the method move_and_slide.
Even the controlled character use move_and_collide, also cause the other one slide.

I also test the same code in Godot 3, not happened. Is it a bug? Or any way to fix it, I just want my npc to collide main character but not be pushed by it just like the kinematicbody2d in godot 3.

try staticbody2d instead, or even AnimatableBody2D. since you dont want it to be pushed by any but still can walk with it by code

thanks for the reply. I just feel strange the behave of the godot4 which is correct in godot3. the kinematicbody canbe moved by other force is counterintuitive.

I was working on a topdown zelda-like game. if I use staticbody instead, I need handle the collision myself to make other mech. that means I need write the physics system on my own.

currently, I use move_and_collide on my npc character to avoid be moved, but the controlled character may still behave abnormally.

Some clarity and additional info on the fix I found useful:

Remove all of the Layers and Masks of your Collision node under your CharacterBody2D (you can delete the Collision node, but the editor will give you a yellow warning symbol). Then add a StaticBody2D as a child of the CharacterBody2D, and a new Collision node under that, give it the same Layer and Mask as your original collision.

1 Like

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