#Issue with CharacterBody2D moving RigidBody2D

3 messages · Page 1 of 1 (latest)

restive swan
#

Hi -- I am having trouble with getting CharacterBody2D to push a RigidBody2D
The scenario is like here: https://baconeggsrl.itch.io/block-runner
The player moves around, I want them to be able to push these crates which are RigidBody2D
I tried this: https://ask.godotengine.org/150548/how-can-i-push-an-object-in-godot-4
But I can't get it to work. Only thing that worked was removing the collision mask but the behavior is undesirable as I want the player to still be able to stand on top of the crates, but be able to push them from the side. (If the mask is removed the crates just shoot out from underneath.) Thank you.

This is my code:

    
    # for moving objects
    for i in get_slide_collision_count():
        var collision = get_slide_collision(i)
        var collider = collision.get_collider()
        if collider.is_in_group("moveable"):
            print(collider.name)
            print(collision.get_normal())
            var impulse = -1 * collision.get_normal() * 500
            collider.apply_central_impulse(impulse)```

The impulse does not seem to do anything
steady wren
#

you can combine Solution 2 and 3 to make it work in 2D