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:
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) );
return;
}
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)