Decreasing the precision of RayCast?

Hi guys,

I am making a game where the player can take objects from the ground. It works like this; a raycast is shot every frame and if it hits a suitable object, the “take” button appears.

The problem is that it gets too hard to aim to the object if it’s too small.

So, I think if I could make the raycast less precise(like a cone), it would be much easier to aim.

If it’s not possible, what other solutions do you suggest?

Sounds like you need to be introduced to Spherecasting.

Guandor, meet Spherecast: Unity - Scripting API: Physics.SphereCast

A SphereCast or CapsuleCast might be more suitable for your situation.

SphereCast Description:

Casts a sphere along a ray and returns detailed information on what was hit.

This is useful when a Raycast does not give enough precision, because you want to find out if an object of a specific size, such as a character, will be able to move somewhere without colliding with anything on the way. Think of the sphere cast like a thick raycast. In this case the ray is specified by a start vector and a direction.

Notes: SphereCast will not detect colliders for which the sphere overlaps the collider. The sphere cast does not work against colliders configured as triggers. If you move colliders from scripting or by animation, there needs to be at least one FixedUpdate executed so that the physics library can update it’s data structures, before a SphereCast will hit the collider at it’s new position.