I’m looking to implement sway to my Weapon Viewmodel’s, i’m struggling as I have never worked with Viewmodel’s in the past and have always struggled quite a bit with math. I’m just looking for the logic and math to achieve what I want, I have already checked out some resources in the past like EgoMoose’s open-sourced FPS System’s weapon sway implementation but it doesn’t achieve the type of sway i’m looking for which should generally affect your weapon rotation; here is an example of what i’m looking for:
Any in-sight to how I would go about doing this and the logic behind it would be heavily appreciated, thanks!
Please read the thread before posting, I have already stated i’m not looking for sway that deals with just the position, i’m looking for a sway implementation that deals with weapon rotation.
Okay, with a little bit of reworking, what HeavenLeigh has linked to there could be used for exactly this.
My interpretation of this solution requires a far more hands-on approach to everything involved, so;
You need two accessible variables per frame: CurrentCF, AdditionalCF. Current is your default, no changes to its rotation. It is your local ‘origin’ point essentially. AdditionalCF is actually a Vector3 your turning into a CFrame.Angle and combing with CurrentCF, to create your rotations.
Take the X/Y inputs from the locked mouse, this is how you’ll calculate your deltas.
Decide how you’re going to rotate your weapon based on these inputs, sounds trivial, but important.
We can now add the X/Y inputs into their relevant AdditionalCF Axis for every movement the mouse does. This will be a fairly large addition if not done correctly, so take some time to mess around with the inputs here.
Now, per frame you’re going to want to do an operation like this; WeaponCFrame = CurrentCF * CFrame.Angles(AdditionalCF)
Thats great, but now we’re stuck with a permanent rotation! Agh! Thats okay though, we can solve that like this; AdditionalCF = AdditionalCF:Lerp(Vector3(0,0,0), .2)
Now our rotation is constantly reverting back to its origin and because its continuosly doing so, it should look really smooth. Unfortunately, we haven’t used any delta operators here, which means people with slower framerates will have their weapon stay rotated for far longer than we may intend.
Anyway, thats the steps you’ll need to go through in order to make this. My version is a little hacky, but thats the price of its assumed readability.