RigidBody2D interact physic with player

Godot Version

4.3

Question

I have a cube that can be picked up or thrown by a player, and it works well. But I also want the player to be able to jump on this item. at the moment, if the player does this, the cube will fall through the textures.
I thought that I would solve the problem if I added staticbody2d to the item, but because of this, it generally flies all over the map now. Please help!

cube code looks like:

extends RigidBody2D

func _ready() → void:
add_to_group(“item”)

var picked = false

func _physics_process(delta: float):
if picked:

  self.position = get_node("../player/Marker2D").global_position
  # Turning off rotation
  self.rotation = 0

func _input(event: InputEvent):
if Input.is_action_just_pressed(“ui_pick”):
var bodies = $Area2D.get_overlapping_bodies()
for body in bodies:
if body.name == “player” and get_node(“…/player”).canPick:
picked = true
get_node(“…/player”).canPick = false
set_deferred(“freeze”, true)
self.linear_velocity = Vector2.ZERO # Speed reset
self.angular_velocity = 0 # Zeroing the angular velocity
break # Exit the loop after finding the player

if Input.is_action_just_pressed(“ui_drop”) and picked:
picked = false
get_node(“…/player”).canPick = true
set_deferred(“freeze”, false) # Enable physics on reset
apply_impulse(Vector2(), Vector2(20, -10)) # Applying pulse on reset

2024-11-05_14-53-00