CharacterBody2D can not move with RigidBody2D on top of it

4.5.1

When a RigidBody2D lands on the players head, when I try to move nothing happens. I saw a reddit thread where someone asked the same question 2 years ago but they had no answer. How do I fix this? The idea of the game is you can throw objects around to complete levels.

You will have to show us your character script. But most likely its causing the character body to experience a collision and probably thinks its hitting a wall something. You could define some sort of collision interaction with the character to bounce the rigidbody back up slightly.

I made some changes to the game so the code is a bit different then what is in the recording but it still has the same issue. One thing that I do notice is that the player moves slightly into the ground when the rigidbody is on top of it. I’m somewhat new to Godot so I’m not sure how I would fix this.

This is the script for the player.

extends CharacterBody2D

const SPEED = 250.0
const JUMP_VELOCITY = -480.0
const GRAVITY_MULTIPLIER = 1.8
var current_speed := 0
var direction := 0
var stuck_in_ground : bool

@onready var player_sprite: AnimatedSprite2D = $PlayerSprite

func _ready() -> void:
	player_sprite.play("cooked")

func _physics_process(delta: float) -> void:
	$HeldObjectCollision.disabled = !Global.player_holding_object
	if not Global.cutscene and not stuck_in_ground:
		if is_on_floor():
			if Input.get_axis("left", "right") != 0 and abs(velocity.x) > 0.05:
				player_sprite.play(str(Global.player_holding_object) + "run")
			else:
				player_sprite.play(str(Global.player_holding_object) + "idle")
		elif velocity.y > 0:
			player_sprite.play(str(Global.player_holding_object) + "fall")
		else:
			player_sprite.play(str(Global.player_holding_object) + "jump")
		if not is_on_floor():
			velocity += get_gravity() * GRAVITY_MULTIPLIER * delta
			
		if Input.get_axis("left", "right") == 1:
			player_sprite.flip_h = 0
		elif Input.get_axis("left", "right") == -1:
			player_sprite.flip_h = 1

		if Input.is_action_just_pressed("jump") and is_on_floor():
			$AudioStreamPlayer.pitch_scale = randf_range(0.9,1)
			$AudioStreamPlayer.play()
			velocity.y = JUMP_VELOCITY

		if Input.get_axis("left", "right") != 0:
			direction = Input.get_axis("left", "right")
			current_speed = SPEED
		else:
			current_speed = current_speed/1.7
		
		if direction:
			velocity.x = direction * current_speed
		else:
			velocity.x = move_toward(velocity.x, 0, current_speed)

		move_and_slide()
		
		for i in get_slide_collision_count():
			var c = get_slide_collision(i)
			if c.get_collider() is RigidBody2D:
				c.get_collider().apply_central_impulse(-c.get_normal() * 30)
	elif Input.is_action_just_pressed("jump") and Global.where_am_i == "main_menu" and stuck_in_ground:
		Global.cutscene = false
		stuck_in_ground = false
		velocity.y = JUMP_VELOCITY/1.5
		$AudioStreamPlayer.play()
		player_sprite.play(str(Global.player_holding_object) + "jump")
		player_sprite.scale = Vector2(0.333,0.333)

This is the script for the object that can be thrown.

extends RigidBody2D

var touching_cursor := false
var being_held := false
const WEIGHT = 1
var no_player_collision := false

func _physics_process(delta: float) -> void:
	set_collision_mask_value(1,true)
	if Input.is_action_just_pressed("interact"):
		if being_held:
			being_held = false
			Global.player_holding_object = false
			if %Player.velocity.y > 0:
				no_player_collision = true
			global_transform.origin = %Player.global_position - Vector2(11,63)
			apply_central_impulse(Vector2(-100 * (int(%Player/PlayerSprite.flip_h)*2 - 1) + %Player.velocity.x * 1.5,-350))
		elif not Global.player_holding_object and touching_cursor and position.distance_to(%Player.position) <= 120:
			being_held = true
			Global.player_holding_object = true
	if being_held:
		rotation_degrees = 0
		$CollisionShape2D.disabled = true
		global_transform.origin = %Player.global_position - Vector2(11,58)
		linear_velocity = Vector2(0,0.1)
	else:
		if no_player_collision:
			set_collision_mask_value(1,false)
			no_player_collision = false
		$CollisionShape2D.disabled = false

func _on_mouse_entered() -> void:
	touching_cursor = true

func _on_mouse_exited() -> void:
	touching_cursor = false