Rigid Body Clipping

Right now I’m having my CharacterBody2D push a RigidBody2D and a hollow box acting as a boundary only for the RigidBody. My problem is that my CharacterBody can push the RigidBody out of those bounds and just clip into it. How do I solve this?

if it could clarify what I want, I’d also like for it to act like a static body and block the player from moving when it is pushed up against a wall.

Does your character push the rigid body because the collision layers/masks are partially incompatible? I.e. your player does not mask the rigid body’s layer? If so you should try to use forces, if you want to stick with a character body for your player you can detect collisions looping through get_slide_collision() and applying a force to any hit RigidBody2Ds. If you want to change your player to extend RigidBody2D you can apply_central_force with a similar velocity/move_and_slide code structure.

They weren’t but now I’ve put them on the same layer and (of course) don’t push each other but now collide. I tried making my player detect if it is colliding with a rigid body and applying force, and it detects it perfectly find, just doesn’t move.

for i in get_slide_collision_count():
	var c = get_slide_collision(i)
	if c.get_collider() is RigidBody2D:
		c.get_collider().apply_central_force(-c.get_normal() * 80)

80 is just temporary value, but is this right?

Also apply_central_force doesn’t even show up in the autocomplete if that matters at all

depends on the mass of the object, 80 might be very low for 2D? I’m using 80 for 3D but those units are in meters not pixels.

You won’t get autocomplete for function returns, you could store c.get_collider() as a variable to get autocomplete again

var collision := get_slide_collision(i)
var collider := collision.get_collider() as RigidBody2D
if collider != null:
    # ...

Turns out it works almost perfectly now, there’s just one goofy part (also yeah my value was really low)

When I push it down it just likes to keep pushing down until I intentionally move up, unlike any other direction where it stops pushing when I release the key. Any clue why that could be?

It also makes my character’s velocity read as 0 when it is clearly moving

Actually as I use this, more problems show themselves. From my player not animating right, to pushing down just not working right, I don’t think this is a viable solution, and I have already tried converting my character to be a rigid body and I would have to entirely rework the code, which is not something I want to do at all.

I kinda wish Rigid Bodies weren’t like this at all. Genuinely quite infuriating

You’re player is detecting the RigidBody as a moving platform, you should set your player’s “motion mode” to floating instead of grounded if you don’t intend to have platformer style movement with jumps and what not; otherwise set the “moving platform layers” on the character to exclude the rigid bodies.

oh… that like actually solved all my problems. Like every single one. Huh. Thanks for your help!

It is very unexpected behavior if you don’t expect it! Even many platformer creators don’t know about the built-in moving platforms functionality