One terry wants to shoot his friend with a finger gun. How do we know if he actually got hit. We need to know where the finger gun is, where it is pointing and how far away do our bullets travel?

Create a game object property and drag any gameobject in.

And a first person shooter this game object is typically your camera It doesn’t have to be

The most simple form of a trace is a Ray. This is just a position and direction in space.

The world transform of a game object has a helper create a Forward ray that represents the position and direction the object is looking.

We build a trace using Scene.Trace and call configuration methods to describe how we want our trace to interact with the world.

.Ray() will be our first configuration method, pass in our forwardRay and a distance then chain call .Run()

Calling .Run() at the end will return information on what our trace might have hit. we are saving this info in the result variable.

We visualize this in the editor by using DebugOverlay.Trace() and pass in our result and a duration for the visual

The trace follows the forward of our gameobject until it hits the wall.

Lets say we want this wall to be invisible to our bullets. Give the wall a tag. then add .WIthoutTags(“ourTag”) to the trace.

This will cause our trace to ignore the wall or any other gameobjects with this tag.

Since we dont want out finger gun to accidently shoot ourself, lets add another configurating method that ignores our game object and anything attached to our gameobject

we can detect hits by checking if result.Hit is true

we can then get a lot of information about what and where we hit. but we only care about the game object.

calling result.GameObject.Destroy() will destroy any game object we hit

but we dont want to destroy any gameobject we hit only the our friend