playMaker

Author Topic: Infinite looping background  (Read 804 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Infinite looping background
« on: June 23, 2021, 02:03:12 PM »
Hiya, it's been a while since I was here. Been crazy busy with work/life.

Anyway...

I'm in the process of re-doing all my backgrounds, and decided to go for the low poly look, which means I have to re-work my FSMs.

Here's the game at the moment - it looks ugly as hell, so ignore that, I'm doing post-processing and lighting another time.


The background is made up of prefabs, which I got from the Unity Store, and have modelled my own elements in Cinema4D too. In this following image you can see I have 3 'depths' of background terrain, with the one selected (6 orange squares at the back).


The challenge is - when the space ship is whizzing left, the terrain prefab at the far right needs to move to the far left, and the opposite if the ship is whizzing right. This cycle needs to be repeated/looped as the ship travels further in either direction.

As a starting point, I have set the 6 terrain prefabs as children of an empty object, used Array List get Children of Game Object.

For moving right, I need to grab object at index 0, move it +1200, then use Array List Move to set the object at index 0 to index 5, for moving left, grab object at index 5, move it -1200, and set object from index 5 to index 0.

Each terrain prefab is 200x200, in the far background there are 6, so that equates to a move of 1200. In the mid background there are 5 prefabs, so the move will be 1000. 

I kinda get all this part, but I'm trying to think of a way of using Get Position (X value) of the Ship, so that every 200 units, it triggers the movement of the background terrain. Actually, triggering the movement of the terrain is no problem, it's getting the steps of 200 right that is causing me a headache.

Like, it sounds simple, but how do i trigger an event only when X goes up or down in steps of 200, infinitely. In fact, it would never actually be infinite because you can run out of fuel, and all the resources are positioned around the x=0  (+or- 500), but the principal is the same.

Any help is greatly appreciated.

Thanks in advance.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Infinite looping background
« Reply #1 on: June 24, 2021, 03:38:43 AM »
Hey Djaydino,

I found this tutorial that you did -


Any chance you could expand on this and help me out if you have any time?

Cheers,

J.

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Infinite looping background
« Reply #2 on: June 24, 2021, 07:10:23 AM »
I think I've cracked it. I'll mark SOLVED once I'm sure.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Infinite looping background
« Reply #3 on: June 24, 2021, 08:30:55 AM »
Hi.
Did the video help out?

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Infinite looping background
« Reply #4 on: June 24, 2021, 10:07:59 AM »
Not really, but mainly due to the nature of the different game styles. I can't use Colliders to trigger the prefab move.

I've kinda got it working, but need to refine it. I'll post here with my results.