skip to Main Content

Tracing multiple objects

In this tutorial I’m going to create a trace for multiple objects. While Unreal Engine provides a set of different shapes that developers can use in this post I’m going to create a sphere. Here is the end result of the tutorial:

endresult

Creating the required C++ Class

First of all, I created a C++ class which inherits from Actor and named it SweepActor. In the header file, I’ve added the following properties with their respective macros:

Performing the Raycast

In order to perform the raycast seen in the first image, we need the following variables:

  • A collection to store all the possible hit results
  • The start location of the trace, which is going to be the actor’s location)
  • The end location of the trace, which is going to be calculated based on the actor’s location)
  • An FQuat which is a way to represent a rotation in a 3D space)
  • The collision channel, which contains information about what we want to trace (ie pawns only, static objects, etc…)
  • The shape we want to trace (in this post: a sphere)

The logic which involes the trace is actually straight forward:

Your output should be similar to the image above plus you will see the names of the hit actors in your console window.

 

 

Avatar photo

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top