raycast and detecting if it did hi

Hello im curently making an FPS shooter. And my bullets are done by using raycast.

Now i want to make computer controlled bots, and i need them to be able to take damage from the user who shoots the raycast.
Therefore i would like to know if it is possible to check if a give gameobject (bots, but lets call it a cube for testing purposes) is hit by a raycast.

have been searching google and the docs but cant seem to find anything, so would be nice if someone would help me :slight_smile:

thanks in advance.

I don’t think it’s possible to check if something is hit by a raycast but you can check to see if the raycast has hit something.

When you are doing your raycast, include a RaycastHit variable which will contain the hit information of the raycast. Then you act upon that accordingly.

Here is an extract from my gun script:

In my “shoot” function
`

RaycastHit hit;
if(Physics.Raycast(rayOrigin, rayDirection, out hit, m_fMaxRange))
{
    ProcessRayHit(hit);
}

`

And my ProcessRayHit function (stripped down)…
`

void ProcessRayHit( RaycastHit hit )
{
	hit.collider.gameObject.SendMessage("DoDamage", m_iDamage, SendMessageOptions.DontRequireReceiver);
}

`

To send damage to my targets I use send message with “DoDamage” as the function name.

Some helpful links: