I am making a 2D point and click game, just for fun.

I want to create some sense of perspective, so I am trying to change the scale of the player as he travels along the Y axis. Obviously, the speed has to change as well (far: moves slow - near: moves faster) to help creating the feeling of perspective.

Here is a GIF of the player moving and changing the scale/speed with my current set-up: enter image description here Is there a math formula to calculate the scale of the character as it travels along the Y axis? And for the speed?

At the moment I am doing:

For scale (ScaleOffset is a value set by every scene, trying to match the perspective manually) :

while (path.Count() > 0)
    var distanceBetweenPoints = lastPosition.DistanceTo(path[0]); 
    if (distance <= distanceBetweenPoints) 
        Position = lastPosition.Lerp(path[0], (float)distance / distanceBetweenPoints); 
        Scale = new Vector2( Scale.Y - ((lastPosition.Y - Position.Y) / ScaleOffset), Scale.Y - ((lastPosition.Y - Position.Y) / ScaleOffset) ); 
    distance -= distanceBetweenPoints; 
    lastPosition = path[0]; path.RemoveAt(0); 
Position = lastPosition;

For speed:

if (speed > max_speed * Scale.X)
    speed = max_speed * Scale.X; 

I know it's not the right thing, but it looks better than without it. However, I want to understand and find the right way to do this.

Am I being crazy? Should I just make the background 3D in order to avoid doing all this jazz? I believe many point and click games do this. An example can be Broken Sword 5 (here you can see the characters moving along the Y axis on a 2D background, changing size and speed https://youtu.be/St_i74zG_ac?si=JcWNkNykjYaaCRae&t=13675)


1 Answer 1


You have the correct idea.

It might be easier to manage if you define the scale at two different points and interpolate/extrapolate it.

For example, if you know that \$Y_1\$ the scale should be \$S_1\$, and at \$Y_2\$ the scale should be \$S_2\$, then you can figure out where your \$Y\$ is relative to those:

$$P(Y) = \frac{Y - Y_1}{Y_2 - Y_1}$$

Here \$P(Y)\$ should be \$0\$ when \$Y = Y_1\$, and \$1\$ when \$Y = Y_2\$, it will be a value in between \$0\$ and \$1\$ if \$Y\$ is between \$Y_1\$ and \$Y_2\$ and it might extend beyond those bounds with either negative numbers (less than \$0\$) or numbers greater than \$1\$.

And now we use that as weight to lerp the scale:

$$S(Y) = S_1 + (S_2 - S_1)P(Y)$$

Then you need to figure out the correct scale for two different points on the plane, and with that you can have the scale anywhere on the plane.

And yes, you could do the same thing for speeds. In fact, since speed is distance over time, and time is not affected by this transformation, the relative change is size on one axis (i.e. the scale factor on one axis) should match the relative change in speed. Thus multiplying the original speed by one axis of the current scale to get the current speed is correct.

Should you do this in 3D? I do not know. Certainly 3D would solve some other issues, but might make some things harder to work with (e.g. rotations). Aesthetically it can look the same (e.g. you can make a 3D scene, with 3D physics, but use billboards/3D sprites to have look exactly the same as you have, and using the same textures), but the workflow will be different, and not knowing the scope of your game and your experience with 3D, it is hard for me to judge if using 3D is better for you.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .