TUTORIAL: Sonic 4 style backgrounds

So it’s been a while since I was last working on my Super Block World game, it had the backgrounds portrayed in an orphographic camera so I had to create my own parrelax script, I know for a fact it could be somewhat difficult to control in very complex situations.

Then I saw the first sets of screens of Sonic 4: Sonic Team’s new 2D platformer that had the graphics with an orphographic (2D) camera for the foreground, but a perspective camera (3D) for the backgrounds.

The results looked really cool and I thought that even though I was using Luxrender to make images at this time I just had to go back to my game and quick implement that style of background (or at least it working for a couple of backgrounds so I could finish and get it working for World2 later), I thought this would be the best way because you’d be able to have great perspective in the background and the 3D nature would automatically take care of the parrelax. How do you do it?

1). Create a seperate scene for your background elements (place the background in the scene), you may use the array modifier to extend it for the entire level.
2). Create your camera that will see the background, face it directly towards the background
3). For the camera, create a property called Distance (so when you get it working you can control the zoom)
4). Set the camera object as the active camera for the scene (otherwise you will get a crappy perspective)
5). Create a reference object in the scene where the gameplay takes place (in my game it’s called “View” and moves with the character (or camera)
6). Use the scene actuator in the main gameplay scene to add the scene with the background as a background scene
7). Create a script file and insert this code (NOTE: the top line is once again required in 2.5), the print line is optional, but it can be used to make sure that you’re getting the right active scene in the list (which must be the scene you’re pulling the object from)

import GameLogic





Px, Py, Pz = ob.position
Vpx, Vpy, Vpz = empty.position

Px = Vpx
Py = Vpy
Pz = Vpz

Dx = Vpx+ob['Distance']

ob.position = (Dx, Vpy, Vpz)


8). Create an always sensor and python controller for the background scene’s camera, have it use the script above

9). If you want to use a different background scene in another level, do not forget to not only link the background scene camera to the other background scene and set it as the active camera, but also to remove the old background scene in the frame before you go to the new level

If you did it right you should see your 3D perspective background come up behind the foreground and move when the character or camera moves, complete with parrelax and all the benefits of the 3D perspective

USEFUL TIP 1: If you need to use the same background for 2 scenes, but need a different object to be the reference in both scenes, insert this code into the script

if "FirstObject" in OL:
<b>elif "SecondObject" in OL:

Copy the bold part and paste it on the next lines as many times as needed to cover all situations.

USEFUL TIP 2: Change the ‘angle’ value in the camera to reduce the perspective effect on backgrounds if needed.

Its weird how people simply let this kind of usefull resource without any post, this is very cool ace dragon I was looking for a specific thread and i saw your script that is very good, thanks for share and it works on the 2.5x version? I m making a totally diferent game here now, but I think that this is very cool.
Thanks for share

Yes, people are lazy and small-minded…they need some candy…
Maybe you could post some screenies or a little blendie for us?..