So I’m currently trying to convert my Unity game over to Unreal. The “hub” of the game is an endlessly driven road and you use a phone to access other areas. So in Unity, I have 3 long road tiles and they just scroll towards the camera at a given speed (scrollingSpeed) and when they get to a certain point (roadSegmentOffsetStart) they just move forward by a certain distance (roadSegmentOffsetDistance).
The road gameobjects are just kept in a list and every frame I iterate through the list and scroll the road piece backwards and check if it’s met it’s threshold to be translated forward, creating an ever scrolling road.
The camera by the way just remains in place. I found a Unreal tutorial of an endless runner game hoping that would help but I couldn’t figure out how to apply that to my use case as their player just ran forward and the road spawned infront of them. Now in Unity infinitely scrolling forward like this throws floating point errors and eventually makes everything disappear as your axis value gets in the millions so I want to fake it by just having everything in place, scrolling it back, and moving it forward when the camera can no longer see it.
How would I achieve this in Unreal Engine
I’m sorry if this was a little ramble, but I’m not entirely sure on what information is useful and appreciate any help.
Unity Script included if that’s helpful at all.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class WorldScroll : MonoBehaviour
{
[SerializeField] private float scrollingSpeed;
public List<GameObject> roadSegments;
public float roadSegmentOffsetStart;
public float roadSegmentOffsetDistance;
private void Update()
{
for (int i = 0; i < roadSegments.Count; i++)
{
//Infinitly Scroll By Set Speed
roadSegments*.transform.Translate(Vector3.back * Time.deltaTime * scrollingSpeed);
if (roadSegments*.transform.position.z <= roadSegmentOffsetStart)
{
roadSegments*.transform.position = new Vector3(0, 0, roadSegments*.transform.position.z + roadSegmentOffsetDistance);
}
}
}
}
Hi man,
you can totally make this road game with the ccamera stand still and the road scroll.
But i would suggest you to mix the two way.
Instead of warp every small piece of road to cycle, (that could be hard keep track of the object and obstaccle you spawn)
Create section of 10 roads, and add a “Gate” to warp back to the origin.
This kind of system you want to use could be impossily complex to set up during curves !
By the way, for making the road scroll toward the camera like you asked:
You can make a new actor with only the camera component in it, use the event begin to “set view target with blend” to set this camera as main.
Now you cant move anymore , if you play with wasd, you could see the defaultPawn move in the level XD
Add another actor and call it road,
add a mesh component of your road ( a straight road, curved roads will be a mess )
Your mesh should be “tile” have something modular to know where snap back, if not, just add 2 roadmeshes, and put them straight.
Now is really simple. lets go in the tick event
You have a road of 100m ? make the a**ctor move with Addrelativelocation by something like 5 **. (suggest you tu get a int and multiply it for the deltatime to have a constan speed at any framerate)
now your road moves endlessy.
Addd a check if he actor position x, or y is larger than 0, if it is, **set actorworld location back to 0 0 0 **
I’m trying to do something similar, but in my case I have 5 BP classes (Possibly more later) that are randomly picked to be generated for segments of the road. I have the infinite road working for when the player is walking down it, but for me, the player will be driving down this infinite road moving at a constant speed not controlled by the player.
The issue that I’m running into is for some reason it only seems to trigger the spawning of the moving road segments 3 times, then stops generating them. (When the part of code that makes it move is disconnected, it infinitely spawns with no issues, but can only be walked down). It also spawns with a tiny gap between the first and second ones (Road Module), then a larger gap between the second and third ones, even though all the placements of all the modular road BPs are precise, and each one is simply a copy of the other, with the foliage and side roads moved around slightly. The cube root and the arrow that are used to indicate the beginning and end of the BP meshes are all in the exact same places as well, so I’m kind of lost on how to fix this.
I’m thinking of ways to just completely restart and make it differently, but if you think you might know of something I could try, any help would be greatly appreciated. I’m not great at BPs, that’s generally what my friend, (the other dev of our game) works on, but I finished up all the 3D asset and environment work, so I’m trying to get into BPs to help him out a bit and just in general to learn more about them for future use.
I have attached screenshots below. (Level BP, Road Module and its Event Graph). Each road module has the same internal structure. (Root is back of module, arrow is front, and box is the invis bounding box around the module, timeline within goes from 0 to 1 over 20 seconds, then repeats (or at least that’s the idea). I wanted this level of control/customization over these since we plan to add some kind of Easter Egg to this section in future, as well as possibly randomized changing street names, but if need be I can try something else and just play the extra stuff by ear.
Thanks for your time and effort helping all of us on here,
-L9