This is not about smooth camera movement I want to know how to check where the player is on the screen so I can move the camera farther in front. my current setup relies on the direction the player is facing to do this but it jolts quickly when I change directions is there a way to make it slowly do it?
If your player is at X 23 Y 48
And you wanna move camera lets say 10 pixel in from of where player is looking
ASSUMING you have topdown game (if it is platformer then simply you care only about X and ignore Y)
For example
W key is pressed (meaning player is facing up)
Change camera position of camera to Player.CenterX() Player.CenterY()-10
Because higher you get lower value of Y you have
Lower you get higher Y value will become
SO if you press S (so go down)
Then you change camera to Player.CenterX() Player.CenterY()+10
D key (moving right)
Change camera to Player.CenterX()+10 Player.CenterY()
A key (moving left)
Change camera to Player.CenterX()-10 Player.CenterY()
Now you adjust that 10 to your needs and you are pretty much set
You can for example check angle of player instead of doing it via key press
Use the lerp function, and lerp the camera co-ordinate from its current position to the target position. So it’s lerp(current_pos, target_pos, change_amount)
, like:
Increasing the change amount will increase the speed at which it moves from current to target positions.