Hey there,
I think I don’t really understand the correct way to use shape traces in Unreal Engine, so I was hoping someone could help me understand.
In my tutorial project I am currently using this Greystone character provided by Unreal in one of the free projects available on the marketplace or fab now. I want to do a box trace to check if the character hit something with his sword. In the skeleton editor of greystone we can see the trace I want to achieve:
I grabbed the location of both sockets in my .cpp code as well as the rotation of the sword_bottom socket. So far so good.
Now comes the confusing part. To do a box trace you specify a start location, an end location and a rotation. This makes sense as you want to specify from which point to which target you want to trace. However, you also specify a box half size and this is where it gets confusing in my opinion.
I would have expected the box half size to be a Vector2D to define the x and y scale of the box, but apparently it is a Vector3D. Why would that be? You already specified from which start to which end location the box should trace, but suddenly you can specify another Z value in the box half size for tracing.
After researching a bit it seems the start and end location of the trace apparently does nothing to the box shape itself. The box shape is defined by the box half size Vector3D and is drawn from the start location to the end location in a way that is not obvious to me. Maybe in a step of 1.f on x, y and z axis? Maybe in a fixed amount of steps as in "draw the box specified by box half size every 1% of the distance until you reach the end location?
This also means that there seems to be two ways to achieve the same trace (or make similar traces at the very least).
Let’s look at the following trace code (Trace 1 box spanning whole sword):
If you take a closer look what you can see is that I calculate the middle point of the start and end location. Then I just specify a box shape with the size of the sword and do the trace. This means since start and end location is the same, I would assume that we check the trace with a single box drawn. The result is the following trace:
This looks correct to me since the trace spans the whole sword as intended.
Another trace, same output:
Given the trace function will repeat the trace from start location to end location you can also specify a small shape and have it repeated over and over again (in a way not obvious to me as explained above). So here is another trace (Trace2, Small box, repeated from start to end):
Taking a closer look at the Z value of the make vector you can see that the box collision shape is very small, just repeated over and over again from start to end location. This results in the following trace:
The result seems mostly similar to me.
I hope the text gave a clear explanation of what I am trying to figure out, so let me summarize the questions I currently have
Questions:
- What are the use cases to prefer Trace 2 (small shape, repeated from start to finish) over Trace 1 (one collision shape)? I would assume Trace 2 to be more performant, but you are welcome to correct me (new to game dev so please do)
- If I do Trace 1 (small shape, repeated from start to finish), in which steps does unreal repeat the shape? I couldn’t find anything in the documentation for that.
Thank you all so much for your help in advance!