Dynamic Shadow with Line Trace | Unreal Engine Step-by-Step Tutorial
I'm going to show you how I implemented a shadow that follows the player. This is very common in games like Crash or even Mario, and its main purpose is to let the player know exactly where the character will land. It's a key visual aid in platform games.
Detect jump states
First, you need to detect the character's states: when it's about to jump, when it's in the air, and when it ends. That's exactly what I have here. The logic starts with the JumpStart state (when it starts the jump), followed by Jumping (when it's in the air), and finally JumpEnd.
I call these events:
- EventJumpStart
- EventJumpEnd
- EventOnLanded
In this case, I use Unreal's Event OnLanded event, which fires when the character lands, i.e., when the jump is completed.
I customized these events. For example, I call EventStart directly in the Event Graph when the jump key is pressed:

You can see it here. The rest of the logic isn't as important; what's relevant is the timing of the call.
Once I've detected that the player is in the air, I can call the EventJumping event. For this, I use the SetTimerByFunctionName node, which allows me to execute a function repeatedly every so often. Instead of a Tick, I use this system because I only want to detect the jumping state, not do continuous processing.
In this case, I call the event every 0.01 seconds, which gives me fine-grained control without consuming too many resources. What this function does is update the shadow's position:

Shadow Settings
First, I have a reference halo (HaloJumpRef), which is a hidden plane positioned on the ground. Although you could use the player's position directly, to avoid extra calculations, I simply use it as a base point.
The shadow moves with the player. I could have used GetActorLocation, but I preferred to use the halo's position as a reference point:

Projection with Line Trace
That's why I decided to use LineTraceByChannel, which is widely used in shooter games. In my case, I project a ray downward, not toward the camera or the player's direction.
This simplifies everything, since I don't have to calculate the direction with a forward vector. The ray starts about 20 units below the player's feet to avoid collisions with itself (I use IgnoreSelf as a precaution).
I set the vector size to -100, since the ray points downward. If you set it to positive, it would point upward, which doesn't make sense for this logic. Just keep in mind that a negative value indicates a downward vertical direction.
The most important thing is the information returned by the Hit Result. We're specifically interested in:
- The actor hit (in case you need additional logic).
- The impact position, which we'll use to place the shadow.
In my case, I take the Z coordinate of the impact (the height) and combine it with the X and Y coordinates of the reference halo, to keep the shadow synchronized with the player.
Visualization and debugging
Activate Debug mode to view the rays, which in my case lasted 5 seconds. This is useful to see what's being projected and if it's working properly.
It's also good practice to print which actor the ray is hitting (Hit Actor). This way, you can see, for example, if it's returning None, which indicates the ray isn't hitting anything.
Projection problem with Line Trace and solution
In some cases, the shadow wasn't projected correctly. For example, when the character jumps, the shadow sometimes disappears or doesn't appear at all. This is because the Line Trace was randomly failing.
After several tests, I discovered that the problem lay in the stage position. Some of my levels had negative positions on the Z axis. By moving the entire stage up (positive position), the problem magically disappeared.
Conclusion
This is how I implemented the dynamic shadow effect that follows the player. It's an extremely useful, simple, and very effective solution for platform games.
In summary:
- The event is triggered every 0.01 seconds using SetTimerByFunctionName.
- It is stopped upon landing using PauseTimerByFunctionName.
- If the Line Trace fails, check the level position.
I agree to receive announcements of interest about this Blog.
I show you how to Make a Shadow Follow the Player with Line Trace in Unreal Engine
- Andrés Cruz