gdquest-demos / godot-4-3d-third-person-controller

Godot 4 demo with a plug-and-play 3D Third-Person Shooter (TPS) character controller inspired by games like Ratchet and Clank.
MIT License
684 stars 76 forks source link

Follow Camera Implementation Preferences #37

Open rhelsing opened 7 months ago

rhelsing commented 7 months ago

I would love to help contribute a toggleable follow camera option (like mario / uncharted) - when the player does not provide look direction input for X seconds, the camera autofollows the player direction. I have implemented this in a separate project, but would like to know if there is a preferred way you would like me to approach this for this project.

General approach in my other project:

  1. visible variable follow_camera, default to false on CameraController
  2. mouse_has_not_been_touched variable, set to false
  3. Timer on camera controller, set to 2 seconds, on timeout, sets mouse_has_not_been_touched to true
  4. when mouse input is detected sets mouse_has_not_been_touched to false and starts the timer

In player script, when follow camera is on and _camera_controler.mouse_has_not_been_touched and player is_moving, (not aiming), have the camera follow the player.

Screen Shot 2024-02-27 at 3 41 39 PM

Please let me know objections/considerations.

NathanLovato commented 6 months ago

Hi, thanks for your interest in contributing to the project! And sorry for the reply delay; we have lots on our plates.

For the implementation, I'd go with either a steering equation (vector calculations) or using spherical-lerp with quaternions perhaps. This would make the code a bit simpler to read and edit.

If you use a timer to check for input, I wouldn't also have a boolean to check if the mouse has been touched. You could instead check if the timer is running or not. I don't have all the code in mind for this project, but I'd also ideally keep the camera code in the CameraController script over splitting logic between the camera and player controller scripts.

Let me know if you have any questions. Don't hesitate to open a PR directly with the change, and if it's okay with you, I could directly edit the code and comment where I'd make changes. That's how we usually do reviews in our team. A little extra note: please use snake case and no abbreviations in variable or function names.