Camera damping in platformer

I’m trying to make a game that looks and feels really polished, and I want to know if there is a way to add camera damping. @richard do you have any tips on this?

2 Likes

can you be more specific about what behavior you’re looking for? maybe give me an example of a game where the camera works like you want?

2 Likes

Basically, a camera with delay. The character will move, and the camera follows slightly later, offsetting the character until you stop moving, when the camera then catches up to the player.

2 Likes

@eugeneredwing8 give this a shot:

it uses @jwunderl’s arcade-sprite-util extension. you can make the camera following slower/faster by changing the 0.96 value. lower values are faster, higher values are slower. make sure you never set it to be 1 or above because that’s when the camera will start moving away from the player (e.g. if you want it slower, try a value like 0.999)

6 Likes

TYSM! this is exactly what I need!

1 Like

a simple way to do it is to set the distance from cam to player as the follow speed. This means that when the camera sprite if 100px away it will move at 100 speed. This creates a simple linear graph. As it gets closer it will slow down and as it gets far away it speeds up: (80px = 80 speed, 50px = 50 speed, 5px = 5 speed)

However this far too slow when close, so it’s helpful to add a base movement speed of to the distance variable. Here I’ve added 50. (notice how y value of the graph shifts up 50 since i’ve added it to all possible distances)
(80px = 130 speed, 50px = 100 speed, 5px = 55 speed)

Another function you can do is just multiply the distance by a constant and then add. Here it’s 2. This increases the steepness of the curve, making the camera follow faster. This also preserves its easing.
(80px = 210 speed, 50px = 100 speed, 5px = 60 speed)

It’s cool to define in maths terms since you can apply simple graphs to it too:
Let y = speed
Let x = distance
The 3 equations are:

  • Simple easing: y = x
  • Simple easing + base speed: y = x + 50
  • Variable easing + base speed: y = 2x + 50

Final equation is y = ax + c
where a = rate of speed increase (gradient)
where c = speed at 0 distance (y intercept)

4 Likes

I swear this basically hieroglyphic

2 Likes

@richard is it all right if I turn this into an extension?

This is exactly why I come to the forums with problems like this, so that I can find ways to fix the problem, but also get info on why it works! thanks!

2 Likes

I know I am not Richard, but I do think it is a good idea turn this as an extension because I did make an extension similar like this, so I do agree you try making this as an extension

1 Like