fix hardcoded raycast distance with viewport object picking

having the raycast distance hardcoded to `10000` caused input events
to not be registered in very large 3D scenes.

This resolves the issue by using the cameras far distance instead.
Creating the more predictable behavior of if an object is visible,
it will be picked by the viewport.

resolves: #49735
(cherry picked from commit 02b6bbc5df)
This commit is contained in:
vdyotte 2021-10-28 23:08:48 -04:00 committed by Rémi Verschelde
parent 824183854c
commit 30f359ee3c
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 2 additions and 1 deletions

View File

@ -647,10 +647,11 @@ void Viewport::_process_picking(bool p_ignore_paused) {
if (camera) { if (camera) {
Vector3 from = camera->project_ray_origin(pos); Vector3 from = camera->project_ray_origin(pos);
Vector3 dir = camera->project_ray_normal(pos); Vector3 dir = camera->project_ray_normal(pos);
float far = camera->far;
PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space());
if (space) { if (space) {
bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, true, true, true); bool col = space->intersect_ray(from, from + dir * far, result, Set<RID>(), 0xFFFFFFFF, true, true, true);
ObjectID new_collider = 0; ObjectID new_collider = 0;
if (col) { if (col) {
CollisionObject *co = Object::cast_to<CollisionObject>(result.collider); CollisionObject *co = Object::cast_to<CollisionObject>(result.collider);