#how to make objects who spawn in walls to be moved outside of walls

1 messages · Page 1 of 1 (latest)

shut fractal
#

I am trying to spawn a bullet that stays on the field after colliding with the environment. it works fine except for when the bullet gets spawned inside of a wall. If so it gets stuck. the enviorment is a tilemap layer and the bullet is characterbody2d

I tried to remove the bullet's mask so that it cant interact with the enviorment and shift it backwards. but its super janky and it feels like there is a better way.

        if collision_info: #prevents crash if there is nothing currently colliding
            if collision_info.get_collider() is TileMapLayer: 
                    velocity = Vector2.ZERO #makes the bullet stop on the environment 
            if collision_info.get_depth() > 1: #this is how i tried to push the bullet out of the wall 
                print(collision_info.get_depth())
                set_collision_mask_value(8,false)
                velocity = Vector2.LEFT.rotated(rotation) * 100
                await get_tree().create_timer(.1).timeout
                set_collision_mask_value(8,true)
            else:
                velocity = Vector2.ZERO
#

if i attempt to change the variables at all it just glitches in place