playMaker

Author Topic: Seamless scrolling for a top down driving game  (Read 9405 times)

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Seamless scrolling for a top down driving game
« on: August 01, 2013, 10:10:35 AM »
Hi everyone,

I'm looking to create a game that would deal with a hovering camera over a moving 2d plane below..  like a 3rd person camera following a car..   the game would actually be fairly stationary, but i need to create the illusion of movement by having the ground scroll seamlessly.  for now a perfectly flat 2d plane would be fine, but of course eventually having terrain would be ideal.. but i'll cross that bridge when i get to it..

I see a number of move actions, but i find them all to be really iffy as the "right" way to get an object to move at a consistent speed..  and be a seemless loop. 

Using gamesalad i would have two tiles..  each would have a "move" behavior that has a variable for spees.. these tiles would be told to move at that speed in a certain direction..  then when either object reaches a certain negative Y position (game is moving vertical) the object would instantly be placed at the top of the screen.. 

I just don't know how to translate that kind of logic to appropriate actions with Playmaker in Unity. 

Thanks!
Caleb

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Seamless scrolling for a top down driving game
« Reply #1 on: August 02, 2013, 12:33:46 AM »
a good example would be zombie highway as seen here http://www.youtube.com/watch?feature=player_detailpage&v=PEQc7M-34PI&t=30

Meathead

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Seamless scrolling for a top down driving game
« Reply #2 on: August 02, 2013, 04:02:54 AM »
I have a very similar question but in a different way you asked it. I was wondering how does the mobile not chew up so much memory with a infinite level like you're example.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Seamless scrolling for a top down driving game
« Reply #3 on: August 02, 2013, 05:55:06 AM »
Hi,

 ok, I created a working sample for this type of game. This is the basic logic, you will have to handle the creation of road items.

WARNING: for efficiency, you might find that using a pool manager will give you better performances, especially on mobile. Here this is just a sample to show you the basic logics behind creation and management of endless roads and the likes.

This sample use two types of system to detect when to trigger an action as the road is moving.

-- modulo operator: as the scene is moving forward, knowing road blocks are 10 units long, I maintain a modulo float that range from 0 to 10 as it moves, which means I always know where I am within the last road block ahead ( 0 at the very beginning, 10 at the very end). I use this modulo to trigger the next road block creation.

-- plain physics trigger. The easiest solution it to maintain a trigger ahead of the camera that would detect when there is no more road. I used this technic to delete previous blocks not visible to the camera anymore. THIS IS CRITICIAL to clean up, otherwise this will leak memory and eventually lead to crash if your play time is long ( you will end up with hundreds of road block, with 99% of it invisible to the camera)

-- also, I have implemented a simple trigger underneath the road to detect when the cube will fall off the road and restart the scene. That's the type of mechanism that can be used to detect when player looses. You can pause the game then,  etc etc.


If you have questions, don't hesitates.


 Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Seamless scrolling for a top down driving game
« Reply #4 on: August 02, 2013, 05:56:47 AM »
@Meathead

In this example, you'll see how memory leak is handled, namely cleaning up road blocks behind the camera. If you do so, then you can let it run for hours with no memory leak.

also, as I mentionned, using a pool manager system is also strongly advised.


bye,

 Jean

Meathead

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Seamless scrolling for a top down driving game
« Reply #5 on: August 02, 2013, 07:10:44 AM »
Thanks Jean you are God of this stuff! Would love to pick at you're brain sometime. You are a great help to this community!
« Last Edit: August 02, 2013, 07:12:38 AM by Meathead »

Meathead

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Seamless scrolling for a top down driving game
« Reply #6 on: August 02, 2013, 09:57:11 AM »
What would be a good way to speed it up for instance I want to speed it up so it gets harder and harder over time.

Also keeping a distance score system now I was thinking I could create a distance from time like they been playing for 2 mins so that = 7000 meters.

I am quite new to programming, by pool manager system what do you mean with that?

Thank You once again

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Seamless scrolling for a top down driving game
« Reply #7 on: August 02, 2013, 10:23:36 AM »
While Jean is definitely a guru on this endless scrolling stuff, I can share a little about pooling and how to adjust speed in general. 

- Pooling is an approach where at the start of your game you create all of the pieces you need in a game.. this saves on cpu and memory which is really important for mobile devices where performance and memory are relatively limited compared to a console or desktop..   so for example with our tiling racing game discussion..  one approach would simply be to spawn new road up ahead and have it come on the screen forever..  but what happens to the pieces that leave the screen?  even if you create some rule to destroy them that doesn't always mean that you get all that memory back without a "garbage collector" which often mobile games lack plus a garbage collector also can take precious CPU cycles..   by pooling you start the game and create the needed tiles.. but instead you hide them off screen..  then as needed the game simply moves those objects on the screen as needed and when not needed they go back to some space off screen.  so nothing is ever created or destroyed (both taking extra cpu power and memory) simply moving things around in the same game space all the time..   Sometimes you can do a mix of things..   pooling is great, but it does add an extra layer of work for the developer unless you use some kind of pooling manager (if one exists, i don't know) that someone else created.  Either way pooling is a good idea, but it is more work.. because now you have to not just make something appear, but you have to be sure you come up with a smart way to track the id of each pooled object so you can logically say..   make tile 1 appear.. now make tile 2 appear..  now make tile 1 appear... etc etc.. 


- Controlling Speed.  This is pretty simple, but also a very important concept that will apply to many other things.  The way you should be able to control the change of speed over time is to make the speed value a variable.  rather than typing in "100" as your game speed and that being permanent.  instead you make a global variable and call it "game speed".  then instead of typing "100" you direct that field to your "game speed" variable.  This allows you to then use other game events to change that "game speed" variable to whatever value you want and this in turn effects the speed of the object because it's always referring to "game speed" not a fixed number "100"
« Last Edit: August 02, 2013, 10:29:04 AM by part12studios »

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Seamless scrolling for a top down driving game
« Reply #8 on: August 02, 2013, 10:33:09 AM »
Jean thanks for sharing the package file for your endless runner..  however i have an uber noob question..  how do i view this as a complete scene?  i was able to import the stuff and see prefabs.  I can see the road for example..  but how do i open this up in a way that lets me see the scene with the playmaker FSMs and such? 

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Seamless scrolling for a top down driving game
« Reply #9 on: August 02, 2013, 10:47:36 AM »
Hi,

 the scene is called "EndLessRoad" and is in the folder "PlayMaker Custom Samples/Logic"

 Are you able to locate it? with this, just hit play and it will run. in there you will find all the fsms dealing with this.

Was it your question?

bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Seamless scrolling for a top down driving game
« Reply #10 on: August 02, 2013, 10:52:14 AM »
Hi,

 Just to comment on part12studios explanationf of pooling:

 pooling is not going to hide things for you, you are responsible ( always) to implement the logic to know when you need to create an item and when you need to destroy it, Pooling comes in with the following:

 when you need to "Create", you ask your pool to "Spawn"
 when you need to "Destroy", you ask your pool to "Despawn"

Spawn and Despawn command will simply "pool" an existing instance in the pool, which prevents the very intensive process of creating objects. when you despawn, you don't destroy, you simply remove it from your scene ( from the visible scene", and it gets stored, inert and disabled, in the pool. So when you need to spawn a new item.

Hopefully that make sense. It' very important to grasp what a pool does and what it will not/never do for you.

Bye,

 Jean

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Seamless scrolling for a top down driving game
« Reply #11 on: August 02, 2013, 11:09:17 AM »
Ok yes I now see the scene!  Thanks! :)

Meathead

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Seamless scrolling for a top down driving game
« Reply #12 on: August 02, 2013, 11:19:29 AM »
Yea as a 3d artist only I am still learning the in's and out's of programming and thanks to playmaker for there great tool it is a great + but still a learning curve with mobile devices. I knew that if you have more stuff in the scene the more it would eat of your platform.

So with a pool I can have presets rdy to be deployed when the player hits a certain trigger such as he runs pass a house.

By having a whole preset of part of a environment hidden until the trigger is hit, does this not still eat the memory of a mobile.

part12studios

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Seamless scrolling for a top down driving game
« Reply #13 on: August 02, 2013, 11:31:38 AM »
yes that is right.  you are effectively pre-loading the game at the start.. and having all the assets needed in a scene present the whole time.  you are trading performance for memory..  and performance is more important than memory for mobile especially. 

Most simple games will not have trouble with memory, but yes if you're trying to make a massive open world exploration game, serious optimization will be needed to insure you manage your memory and performance together.