Dragrigidbody distance

Im making a horror fps game, in which i want the player to be able to pick up rigidbodies and to move them around, just like in the Dragrigidbody script. But the thing about the Dragrigidbody is that it has unlimited distance to the rigidbody. So as long as i can see the object i can pick ut up. Is there any way to set a maximum distance?

Im not that into scripting, so you’ll have to excuse me if I ask stupid question.

If there is no way to alter the script, is there another good way to make a similar feature using different techniques?

Next time add some code… It’s much easier to give an answer if you can see exactly what’s going on.

In your case, if you look at the script you have some lines where you raycast against objects.
The syntax for Physics.Raycast used here is:

static function Raycast (ray : Ray, out hitInfo : RaycastHit, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers) : bool

That function, as it is used in DragRigidbody, has a parameter that limits the raycasting to 100 units:

// We need to actually hit an object 
var hit : RaycastHit; 
if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), hit, 100)) 
return;

You just need to change it to the distance you want to limit the dragging effect to. That way, anything farther away will simply not be hit by the ray and the break statement will prevent the rest of the code to run on that object. And even if it hits some other object, the list of objects returned in the “hit” variable will include only objects within the distance.

I’ll do that next time.

And thanks for the answer, it helped a alot.