Revision Difference
Traces#543825
<cat>Code.Misc</cat>
<title>Traces</title>
# What are traces
Traces are imaginary lines. When you run a Trace you get a TraceResult - which tells you what the line hit.
So for example, if you, as the player, wanted to spawn a box. You'd run a Trace from the player's eyeball to 200 units in the direction that the player is looking. The TraceResult would show that it hit a point and now you know where to place the box.
<upload src="a61e9/8d9152587ef3390.png" size="16905" name="image.png" />
<validate>Added new image, are the info with the units correct?</validate>⤶
<upload src="653cb/8d91535fbaeba6e.png" size="229669" name="rays.png" />
⤶
In the above example: the blue ray is what is inputted into `Trace.Ray`, and the red ray is the `TraceResult` from the ray. Note that the end position in the `TraceResult` struct returns where the ray hit. The `Distance` field also gives you the distance of the ray from the start point.⤶
# Tracing
Traces are constructed using the Trace static functions, and configured using members. You run the trace and get the result using Run().
```
var mytrace = Trace.Ray( startPos, endPos );
mytrace = mytrace.WorldOnly();⤶
mytrace = mytrace.WorldOnly();<upload src="653cb/8d915359eda14aa.png" size="615337" name="rays.png" />⤶
var result = mytrace.Run();
```
The configuration functions return a new object. This is a convenience thing, so you can format like this:
```
var tr = Trace.Ray( startPos, endPos ).Run();
```
or like this
```
var tr = Trace.Ray( startPos, endPos )
.Ignore( playerEntity )
.Ignore( playerVehicle )
.Size( 10 )
.Run();
```
## Size
In the example above the Size describes the size of an AABB to trace.
This means instead of tracing a simple line, you're tracing a bigger cube along the line.
# TraceResult
The Trace Result is a simple struct. It gives you information on the hit.
Here you can see testing whether the trace hit and using the hit position to spawn an entity 10 units above it.
```
if ( tr.Hit )
{
var ent = new ModelEntity();
ent.Pos = tr.EndPos + tr.Normal * 10;
}
```
# TODO
Explain how to trace using other shapes