flame icon indicating copy to clipboard operation
flame copied to clipboard

Is it possible to make the camera smoothly follow the player?

Open devchenli opened this issue 2 months ago • 7 comments

Problem to solve

The camera's movement is too jerky when it follows the player.

Proposal

It would be great to have a smooth camera movement option with adjustable smoothness parameters.

More information

No response

Other

  • [ ] Are you interested in working on a PR for this?

devchenli avatar Apr 27 '24 05:04 devchenli

It depends on what the camera is following. If the component it is following moves smoothly, the camera should move smoothly too.

ufrshubham avatar Apr 27 '24 05:04 ufrshubham

Just set the maxSpeed argument in camera.follow to something lower and it will move smoothly.

spydon avatar Apr 27 '24 08:04 spydon

Just set the maxSpeed argument in camera.follow to something lower and it will move smoothly.

Thank you, I think I understand what you mean. However, unfortunately, setting the speed alone is not enough. If you have used Cinemachine in Unity or the Position Smoothing and Drag properties of the Camera in Godot, you will see that they achieve a very good effect. Similar to the protagonist in a movie, when the player only moves a short distance, the camera remains stationary. However, when the player moves a sufficient distance, the camera will follow the movement and accelerate smoothly linearly like a movie lens, rather than simply following the player's movement exactly.

devchenli avatar Apr 30 '24 07:04 devchenli

However, when the player moves a sufficient distance, the camera will follow the movement and accelerate smoothly linearly like a movie lens, rather than simply following the player's movement exactly.

IMO, this can be easily achieved by introducing a follower component which implements these custom following logic. So FollowerComponent tracks Player and camera simply follows the FollowerComponent normally.

It might also be worth it to create a new package similar to cinemachine instead of adding more code to the existing camera.

ufrshubham avatar Apr 30 '24 08:04 ufrshubham

It might also be worth it to create a new package similar to cinemachine instead of adding more code to the existing camera.

Maybe we should add a curve argument for the movement, I think that should do it too.

spydon avatar Apr 30 '24 08:04 spydon

The expected camera movement is like this :

https://github.com/flame-engine/flame/assets/46481943/bafd8833-e711-41cb-88c7-f7886c2c790f

I would really appreciate it if this functionality could be implemented either by creating a new package(like unity) or adding a curve argument for the movement (like godot) . Thank you all for your consideration.

devchenli avatar Apr 30 '24 09:04 devchenli

I implemented this on Turi by having an invisible position component as constant camera target. Then, by apllying Effects to this component's position (with curves), one can have such effect.

Video for reference: https://twitter.com/i/status/1717496557422141465

renancaraujo avatar Apr 30 '24 11:04 renancaraujo