I’m currently working on a project where I need to create a “snake game”-like effect using lights in Unreal Engine. The idea is to have a sequence of 3 lights moving continuously around a circle of 10 lights. Once the sequence reaches the end, it should wrap around to the beginning and continue.
Here’s a brief description of what I’m aiming to achieve:
Initially, the first 3 lights are on while the others are off.
In the next step, the sequence moves by one light, turning on the 2nd, 3rd, and 4th lights, and turning off the rest.
This continues such that each step moves the “snake” of 3 lights forward by one position.
When the sequence reaches the end of the array, it should wrap around to the beginning (e.g., if the last lights are 8, 9, and 10, the next set should be 9, 10, and 1).
I’ve attempted to set this up using a Timeline and some Blueprint logic, but I haven’t been able to get the wrapping around and continuous movement quite right. Could anyone provide a detailed Blueprint setup or guide on how to achieve this effect?
Any help or guidance would be greatly appreciated!
Create a grid of 10x10 blueprints with a light component (or use a default light actor with a custom component) with a float variable to keep track of the time to turn off.
Create a manager or pawn that continuously moves through the rows and columns at a specified interval. On each index it lands, turn on the light and add the interval time to the float. Wrapping around the indices for rows/columns is straightforward. The tail effect is achieved by keeping the light on for several ticks based on the float value. The longer the time added to each light, the longer the tail.
In the pawn/manager tick function, add the current index to an array and loop through the array, decreasing the float value by the elapsed time. If the float is <= 0.0, turn off the light and remove it from the array.
Use a “fixed time step loop” to update the game. This is in case the snake needs to jump several indexes per frame (go faster).
To check for collisions, see if the float at the current index is greater than 0.0 to determine if the snake has collided with its own tail.
I’m sure there are more than one way to approach this. Let me know if you have any questions.
Thanks for the reply! I’m new to Unreal so currently still getting familiar with blueprint. Could you provide a few screenshots on how this is implemented? Thanks so much!