There are many ways to do a raycast in Unity. For this example, we'll use the overload that takes an Origin, a Direction, and a Max Distance and returns a Hit Info:

The node looks like this:

As you can see, unlike usual nodes, we have two outputs: a boolean, indicating whether the raycast hit something, and a hit info, giving us much more information about the hit.

You can use the inputs you want to get your raycast, but let's focus on how to get the values out of the hit info.

You can use an Expose node to decompose any type. In this case, we want Expose Raycast Hit:

You can then connect that node to the hit info port to expose it:

Here, for example, we have access to the Point that was hit, the Distance the ray traveled before hitting, and the collider / rigidbody / transform of the object that it hit, among many other properties.

You can use these to react to the raycast accordingly. For example, this graph does a raycast in front of the current object when we left click, and if it hits an object, it spawns an explosion particle system at the impact point and destroys the impacted object:

This article was helpful for 23 people. Is this article helpful for you?


If I wanted to do the same thing for Transform Get Up but want Get Down as Get Down is not a thing, how do I get this direction

I came up with this and I now have a debug ray. It works but the problem is I need the Debug.Ray and Raycast to rotate with the ship. Any help would be useful.
Happy coding (or is that drawing).

I may be late, but would using Expose raycast help?


Is there a reason why the get collider block keeps giving a null? I'm trying to detect the player in order to shoot something. 

I get the same error as Nat Crawford