Page 1 of 1

Smooth foreground/background scaling (a la Downhill Supreme)

Posted: Thu Jan 30, 2014 5:56 am
by therealcos
How did you create the smooth, dynamic scaling of both the foreground and background layers in Downhill Supreme?

I've already tried to do something similar with a project of my own by setting the scale of the each layer equal to the speed of a given body times a constant, but this has produced a really jittery result (i.e. the frame, which should be following the body, jumps around with every step). How did you achieve the effect of zooming in and out on both the foreground and background so smoothly in Downhill Supreme and how can I go about doing the same in my game?

P.S. - Also, I'm wondering (I can't really tell) if Downhill Supreme makes use of an effect that simulates a "slow camera" that appears to smoothly catch up to the position of the bike, but isn't constantly fixed perfectly on it. If so, how did you achieve this? I feel like the logic behind this sort of smooth movement might be related to my original question...

Re: Smooth foreground/background scaling (a la Downhill Supr

Posted: Thu Jan 30, 2014 2:01 pm
by iforce2d
Yes, it's a 'slow camera' type of method.

First a focus point is found. This is a point ahead of the rider that the player will need to see, in order to be have enough time to see what's coming up. This is done by casting ten rays down from 'heaven', to sample the area in front of the bike, as shown by the red lines in the screenshot here: viewtopic.php?f=4&t=200&p=783#p797 This sample area is moved forward and expanded a little depending on the current speed of the bike. The focus point is then restricted to a maximum distance away from the rider.

A layer scale is calculated such that when the view is centered on the focus point the rider will still be visible, and this new scale value is clamped between a min/max value. The layer scale is set to smoothly catch up to this new scale value.

The clamping may cause the rider to now be off-screen, so finally, the view is moved so that the rider is visible, also done by the smoothly catch up.

The smoothly catch up thing I usually do like this:

Code: Select all

float uptake = 0.05;
value = uptake * newValue + (1 - uptake) * currentValue;
... where 'value' can be the layer scale, or the view position etc. When 'uptake' is 1 the new value will be fully applied immediately, and smaller values apply it slower.

As for the background, I have no idea what's going on there but it looks ok so I left it that way. I didn't really like having no idea about it though, and as it happens just today I have been reworking this part of the game for DHS2. It will have a more typical parallax scrolling background this time.

Re: Smooth foreground/background scaling (a la Downhill Supr

Posted: Sat Feb 01, 2014 1:06 am
by therealcos
Ahhh ray casting - genius!

I tried the 'uptake' equation for smooth zooming and it worked great! Thanks so much!