I know some games like awkward car ride - Roblox has a moving background. Essentially player spawns in a car but only the background moves. How can I do this?
Thanks for the suggestion, but it seems to be too vague. Yes I’ve thought of using TweenService or CFraming but how would the script look like?
You can just get a position where the background should end up stopping, or just constantly move it in a loop, first option’s what I would go with:
local tweenService = game:GetService("TweenService")
local background = -- define background
local goal = {}
goal.CFrame = -- post goal cframe here
local tweenInfo = TweenInfo.new(
-- fill your info
)
local tween = tweenService:Create(background, tweenInfo, goal)
tween:Play() -- here starts the visual
Let’s say the background is 5000 studs long. How do I prevent the game from lagging?
In the game you linked you can clearly see that the map just deletes itself after moving a certain distance past you, and then loops. This is likely the best way to make this effect.
Tween doesn’t lag at all, and just for increase of performance you can tween it on the client’s side to avoid server lag.
This won’t work because what each player experiences won’t sync and I need the game to sync.
This sounds pretty good how should I do it? Do I spawn a new map every time the previous one ends? If that’s the case, I’ve heard multiple developers telling me not to do that because it will result in lag.
That is crap, if there talking about lag there computers are actual toasters. Deleting a basic background map will not cause lag, especially TweenService.
The only reason it would cause lag if there computer is running OpenGL, it must be like 10 years old.
It won’t be a main cause of lag if you do it properly. Also, rather than deleting and cloning new parts, you should move them very far away out of render distance and then just put them back in when you need them again. Deleting things is pretty cheap performance-wise, but cloning or instancing new parts/scenes is much worse for performance if you do it often.
For movement, TweenService is one possibility, but CFraming them every RenderStepped (or using one of the new RunService functions) should work nicely too.
For bonus optimisation points you can use :BulkMoveTo() to move the scenes if you’re cframing them, but it probably won’t be lagging by this point anyway, so it’s probably unnecessary.
I’m curious, is there any way how to change the render distance regardless of graphic levels?
Using StreamingEnabled you can, but that’s not what I’m talking about. You can just position them VERY far away (like, hundreds of thousands of studs). Careful not to position them too far though otherwise you’ll start getting floating point errors, though I’m not sure how much this’ll matter if the scene is moving anyway.
How big is does this background need to be? Outdoors scene?
I made a demo ‘train’ with a moving beam background, might work for close/small proximity wall backgrounds.
https://www.roblox.com/games/6505746647/Beam-Train-Demo
You do know that opengl is a specification lmao