Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RayCast3D.get_collider does not return a CollisionShape3D #100139

Open
Niriel opened this issue Dec 7, 2024 · 1 comment · May be fixed by #100394
Open

RayCast3D.get_collider does not return a CollisionShape3D #100139

Niriel opened this issue Dec 7, 2024 · 1 comment · May be fixed by #100394

Comments

@Niriel
Copy link

Niriel commented Dec 7, 2024

Tested versions

  • Reproducible in: v4.3.stable.steam [77dcf97]
    and probably everything before that.

System information

Godot v4.3.stable (77dcf97) - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2060 SUPER (NVIDIA; 32.0.15.6603) - Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz (8 Threads)

Issue description

The documentation of RayCast3D makes it clear that it is meant to detect collisions with CollisionObject3D:

Class: RayCast3D
Inherits:  Node3D <  Node <  Object
Inherited by:  BdMousePick

A ray in 3D space, used to find the first CollisionObject3D it intersects.

Description

A raycast represents a ray from its origin to its target_position that finds the closest CollisionObject3D along its path, if it intersects any.

However, the method RayCast3D.get_collider returns an Object, not a CollectionObject3D as one would expect from the documentation.

Casting that Object to CollisionObject3D does not work with constructive solid geometry. Indeed, get_collider can return a CSGShape3D which cannot be cast to CollisionObject3D.

Steps to reproduce

  • Point a RayCast3D node at a nearby CSGBox3D.
  • Give the RayCast3D node a target_position that ensures it reaches the box.
  • Tick use_collision on the CSGBox3D node, under CSGShape3D.
  • Add this script to the RayCast3D node:
extends RayCast3D
func _physics_process(_delta: float) -> void:
    var hovered_unclear := get_collider()
    var hovered_collision_object_3D := hovered_unclear as CollisionObject3D
    if (hovered_unclear and not hovered_collision_object_3D):
        push_error("TypeError: RayCast3D.get_collider() returned a node that is not a CollisionObject3D")
        assert(false)  # Or place a break-point on the previous line.
  • See in the debugger that hovered_unclear is a GSGBox3D.

Minimal reproduction project (MRP)

raycast3d-get_collision.zip

@rburing
Copy link
Member

rburing commented Dec 7, 2024

Yes, the documentation is wrong (too narrow). In addition to CSG there's also GridMap. Fixes to the documentation are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants