I was watching back to some of Aaroncy’s old berserker videos and I realised I really like the way the camera works and how it changes between in and out of combat and how it works in general. I understand how to make a change to the camera between combat and out of combat but from a general standpoint how would I make a camera system like that.
Here is a video for reference (warning there is swearing and blood):
Sorry for the late reply.
This looks like some simple lerps with a camera system
Is this what you are looking for?
Lerp time is a bit exaggerated for this example and the dot is placed for reference:
Sorry in advance for the not so great video quality, had to compress it.
You only wanted to know how the camera works so I didn’t bother adding a custom character system for locking character rotation, same goes for the camera combat state because you said you know how to implement that so I bound it to a key
If I’m understanding this correctly then yes
Here’s a showcase with a rushed dodge mechanic Is this what you are looking for?
I gave the lerp a more regular speed in this example and after doing a few small dodges I did a large dodge to show that the camera does go faster the further away you go from it
If this is correct then I would gladly write an explanation with the source code!
We aren’t doing any collision checks so the camera could go through obstacles
The player and target should never be on the same X and Z positions which would possibly cause unexpected behavior
I am not the best in explaining things so the source code is at the bottom if you don’t understand
Explanation
Regular camera system
Do we need a custom camera system?
In this case it would be nice to have a custom camera.
A custom camera would make it easy to write the lock on system.
For this I am going to expand upon a camera system that I made some time ago.
This camera uses spherical coordinates.
You can read about that from a previous post I made:
Make sure you read the edit and not the outdated source
Lock on camera
Why we needed this system
Lock on camera
The person in the video probably used 2 look at functions.
One for the player and after getting the back, up and right vector he set the camera position and look at. Of course this is just an assumption.
Personally I prefer this approach but you can use the other one if you want. All up to preferences ofcourse.
Locking the player rotation?
Apparently you can just use a CFrame lookAt without making movement janky if you disable AutoRotate.
Simply just make a look at and apply the CFrame to the root part.
Initialize services: Players, RunService, UserInputService
Get the current camera and set its type to Scriptable
Initialize variables:
subjectPosition, targetPosition as zero vectors
locked as true
lerpSensitivity, sensitivity, radius, theta, phi with given values
Define function SphericalCoordinate(r, theta, phi):
Calculate Position, Hat_r, Hat_theta, Hat_phi using trigonometric functions
Return a dictionary with Position, UpVector, LeftVector, FrontVector, DownVector, RightVector, BackVector
Define function LookAtSphericalCoordinate(r, eye, target, xOffset, yOffset):
Adjust r using the distance between eye and target
Calculate dx, dy, dz as differences between eye and target coordinates
Calculate theta and phi with offsets
Calculate Position, Hat_r, Hat_theta, Hat_phi using trigonometric functions
Return a dictionary with Position, UpVector, LeftVector, FrontVector, DownVector, RightVector, BackVector
On UserInputService.InputBegan:
If the input is processed, return
Toggle locked if L key is pressed
Move character right if E key is pressed
Move character left if Q key is pressed
If input is not MouseButton2, return
Lock mouse position
On UserInputService.InputEnded:
If the input is processed, return
If input is not MouseButton2, return
Set mouse behavior to default
On RunService.RenderStepped:
If there is no local player character, return
Get character and target
Get mouse delta for movement
Update theta and phi based on mouse delta
If locked:
Set targetPosition to target's position
Lerp subjectPosition towards character's head position
Disable character auto-rotate
Calculate LookAt CFrame for character to face the target
Set character's CFrame using LookAt matrix
Calculate spherical coordinates using LookAtSphericalCoordinate
Lerp camera's CFrame towards calculated spherical coordinates
Else:
Lerp subjectPosition towards character's head position
Enable character auto-rotate
Calculate spherical coordinates using SphericalCoordinate
Set camera's CFrame using spherical coordinates and subjectPosition
Source and setup for reference
Source code
Here’s the source and how to set it up
This is here for reference the code is a little rushed. Make sure you do some clean up before making it an integral part of your game/experience!