Perhaps what you could do is multiply the Camera CFrame with an offset, which should create your desired camera shake effect. Something like this can work:
CurrentCamera.CFrame *= CFrame.new(number x, number y, number z)
The numbers x, y, z should correspond to the components of your offset vector.
One thing you’ll have to accommodate for, however, is reversing the effect of the offset so that the camera doesn’t endlessly drift off toward a direction when you use an attack. For example, if you offset the camera 3 studs to the right, you’d then want to offset it 3 studs to the left so that it doesn’t keep drifting off to the right. After the action is finished, you can set the offset to zero.
Rather than tweening the CFrame, make sure you tween the offset itself. Setting the camera CFrame with the offset should be done in a RenderStepped event.
Sorry, but I don’t see a property of the camera called offset. If you’re referring to the property of humanoid called CameraOffset, then I already tried that and included it in the original post.
By offset, I mean a custom Vector3 variable in your code that you multiply with the Camera CFrame. What you can do is tween it to (3,0,0), then to (-6,0,0), then finally to (3,0,0). This should cause it the camera to go right by three studs, then left 3 studs, then back to its original position. Make sure that you don’t tween the Camera CFrame though, just the offset variable you declare yourself inside your code. Instead, make sure to update the camera in a renderstepped to make sure it doesn’t fall behind. Sorry about the confusion.
I think I’m even more confused, I’m not sure what you mean by this. You want me to tween a variable, but tweenservice:Create() only accepts instances as the first parameter. And if you instead are telling me to multiply the camera by this CFrame using runService, I have no idea how I would write that.
Sorry about that. Huge oversight on my behalf. You can tween a Vector3Value, which is an actual object containing your offset that can be tweened.
As for the renderStepped, here is what you can do:
This code updates every frame so that the Vector3Value, which defines the offset, is applied to the camera (hence the name renderStepped). In a separate line of code, you can then tween your Vector3Value offse.
Thank you for clarifying, and it does work, but the results look about the same as just tweening the CameraOffset property of humanoid. This isn’t exactly what I was trying to achieve, as in the clip I sent, the camera doesn’t seem to be just moving left or right, but rather following the player’s head. Now if it is just moving left and right, it could be that I might have to tweak the tweenInfo used on the tween:
Hmm, this is a tricky one. Try checking if there are any other scripts (maybe a bob script) you have that are using the Humanoid’s camera offset and, if so, be sure to alter/remove it so that the player’s head on the y direction is not followed.
For example:
Keep the camerasubject to the humanoid.
Track the position of the head/sword/whatever
LERP the camera cframe in comparison to the position you are tracking. Lerping would make it more smooth.
Also you can use that tracked position to add angles to the offset
Lerp is a great idea, though sort of hard to implement because of the jittery effects it can cause (especially with the camera). Regardless, I agree that it can be very smooth, as long as the implementation is optimized to accommodate for the jitters.
In My opinion, I would try to create an invisible part that you can animate and make the humanoid camera offset tween depending on the offset of the part to the humanoid part. So if the part was offset to the humanoid root part by (1, 0, 1) the CameraOffset in the humanoid would tween to (1,0,1). This would allow fine control of how the camera shifts, also allowing you to use tweening styles to customize the speed / easing of the camera movement.
To create the animatable part I’d create a rig with a new root part and a single part connected with a Motor6D and weld the new root part to the character’s root part and make them have no collisions or weight.
Sorry, but I don’t see how this is any different than just tweening the camera offset. If the cameraOffset is linked to the part, then wouldn’t just tweening the camera offset achieve the exact same effect?
Yes, but instead of tweening it to follow a specific limb of the player it would be linked to an invisible part that you have fine control over, allowing you to smooth out the jittery movements and make the camera sway in the directions you want.
its pretty simple, its built into roblox.
Example:
CFrameVar = CFrameVar:Lerp(CFrameVar + Vector3.new(5, 0, 0), 0.5)
I don’t know how to explain it but lerping by a factor of 0.5 will change the CFrameVar to the midpoint between CFrameVar and CFrameVar + Vector3.new(5, 0, 0).
A factor of 0 will make no change and a factor or 1 will set it to the value you are lerping to.
You can make a renderstepped loop that lerps the cframe of the camera to your target cframe, it will make quick changes the movement smoother
So after doing a bit more research, it seems like they are actually just setting the camera subject to the character’s head. The reason why it didn’t look as intended when I did it was just because of choppy animations. I was having a problem where changing the camera subject to the head broke shiftlock, but I checked this post: How to get shiftlock to work with head?
and figured it out. Thank you for the suggestions, but it was a lot simpler than I thought.
Here’s how it looks now: (using my combat system)
Generally, this simple change makes combat animations look way better.