CollisionShape3D problem with Rigidbody3D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Geri

Hello,

I’m new to Godot (Version 4.0.2 stable) and wanted to create a small 2.5 platformer. I created a gridmap (my ground layer), a simple player controller (CharacterBody3D) and a box (RigidBody3D). The goal is for the character to be able to pick up the box, walk around with it, and throw it. That worked quite well (Picture 1 and 2).

Picture1

Picture2

Unfortunately, the following problem occurs. As soon as I pick up the box, the CollisionShape3D of the box seems to disappear. Because the box no longer collides with the ground (Picture 3). If I let go of the box then it works again and the CollisionShape3D is back.

Picture 3

Here are my collision layers:
1 = Ground
2 = Player
3 = MoveBox

Collision Mask:
1 & 2 & 3 = Ground
1 & 3 = Player
1 & 2 = MoveBox

The box has received the class name MoveBox. Below is my script for the player:

extends CharacterBody3D

const move_speed = 6
const jump_velocity = 7
const gravity = 20

var held_object: MoveBox

var character
var raycast
var hold_position

func _ready():
	character = get_node("PlayerAnimation")
	raycast = get_node("PlayerAnimation/RayCastPlayer")
	hold_position = get_node("PlayerAnimation/HoldPosition")

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta
	
	# Jump
	if Input.is_action_just_pressed("Jump") and is_on_floor():
		velocity.y = jump_velocity
		
	# Pick up, Move and Throw Object
	if Input.is_action_just_pressed("holdObject"):
		if held_object:
			PhysicsServer3D.body_set_mode(held_object, PhysicsServer3D.BODY_MODE_RIGID)
			#held_object.freeze_mode = 0
			#held_object.collision_mask = 1 # enable collisions with layers 1
			held_object = null
		else:
			if raycast.get_collider():
				held_object = raycast.get_collider()
				PhysicsServer3D.body_set_mode(held_object, PhysicsServer3D.BODY_MODE_KINEMATIC)
				#held_object.freeze_mode = 1
				#held_object.collision_mask = 0 # disable collisions with all layers while holding
	
	# Object to "hold position" to player
	if held_object:
		held_object.global_transform.origin = hold_position.global_transform.origin
	
	# Player movement
	var input_dir = Input.get_vector("moveLeft", "moveRight", "ui_up", "ui_down")
	var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		velocity.x = direction.x * move_speed
	else:
		velocity.x = move_toward(velocity.x, 0, move_speed)
		
	move_and_slide()
	
	# Player rotation
	if direction.x < 0:
		character.rotation_degrees.y = -180
	if direction.x > 0:
		character.rotation.y = 0

I’ve tried a lot, including changing the collision_mask or freeze_mode or half of the code :slight_smile: Unfortunately nothing helped. Is it my fault or a bug in Godot4?

Thanks for tips and help.

Cheers Geri