godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.17k stars 20.22k forks source link

set_as_top_level behaves weirdly for CollisionShape3D #66710

Open CoreTaxxe opened 1 year ago

CoreTaxxe commented 1 year ago

Godot version

4.0-beta 2

System information

Windows 11, Vulkan, RTX 3070 V. 516.94

Issue description

set_as_top_level(true) produces weird behavior on CollisionShape3D. It appears as if the transform is not global but rather some kind of mixture of direct parent and parent.parent.

Toplevel false : proper alignement image

Toplevel true : collision shapes position is changed by roughly half its displacement from local transform prior. Does not happen with the mesh, even if the mesh has an offset as well. image

when the root objects position is changed and top-level is set true the displacement becomes even more pronounced. It appears as if the collisionshape adds the roots transform twice to its own transform.

image

when moving the root again with top-level set to true the mesh remains at its global position but the collisionshape moves along without changing its local space. image

Setting top-level to false again moves the collision shape to its correct position image

Node Setup : (it can also be a direct child of node3d and returns the same results) image

Controls :

var toggle = false

func _physics_process(delta):
    if Input.is_action_just_pressed("ui_accept"):
        toggle = not toggle
        label.text = "Toplevel : " + str(toggle)
        mesh.set_as_top_level(toggle)
        shape.set_as_top_level(toggle)

    if Input.is_action_just_pressed("ui_left"):
        global_transform.origin.x -= 1

    if Input.is_action_just_pressed("ui_right"):
        global_transform.origin.x += 1

Steps to reproduce

  1. call set_as_top_level(true) on any collisionshap3d and move its parent object.

Minimal reproduction project

TopLevelCollisionShape.zip

MemoriesIn8bit commented 3 months ago

I'd like to add that this bug still persists in 4.2.2-stable (tested on Windows 11).