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

View file

@ -647,10 +647,11 @@ void Viewport::_process_picking(bool p_ignore_paused) {
if (camera) {
Vector3 from = camera->project_ray_origin(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());
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;
if (col) {
CollisionObject *co = Object::cast_to<CollisionObject>(result.collider);