im trying to achieve weapon sway like Games Unite (video below) but im not very good at doing this kind of stuff. I have tried searching for solutions on the devforum and doing it myself but i couldnt find a solution that achieves this exact effect.
yes, i have the framework set up pretty much. im using a spring module for the current sway. i can send the script over, but its not finished in its current state as i was trying out different things.
It isn’t clear in your video which affect you’re looking for but anything that involves “making the gun move” while the player/camera moves is likely going to be done with animation. There may be other ways to do it e.g. scripting tweens on the model(s) but I’d probably explore the animation route first.
They way I have it set up is ClientGun is the main Gun script
The “SetGunPosition” modules runs through each of it’s modules and calculates it’s CFrame offset
They all get added together at the end to set the gun’s final position.
For the gun swaying, I set an offset in “SetGunPosition.Rotation” module
Here’s how it looks in the explorer:
Here is the “Rotation” module’s code
local UIS = game:GetService("UserInputService")
local Camera = game.Workspace.CurrentCamera
local LerpFactor = .2
local StickFactor = 10
local MaxRot = 80
local Dampening = .5
local LastCF = CFrame.new()
local function ToRad(Number:number)
return math.rad(
math.clamp(
Number*Dampening,
-MaxRot,
MaxRot
)
)
end
return function(GunModel:Model,Tool:Tool,Character:Model)
local GamepadState = UIS:GetGamepadState(Enum.UserInputType.Gamepad1)
local ThumbstickRotation = GamepadState[18].Position * StickFactor
local Delta = Vector2.new(-ThumbstickRotation.X,ThumbstickRotation.Y) -UIS:GetMouseDelta()
local Offset = LastCF:Lerp(
CFrame.Angles(ToRad(Delta.Y),ToRad(Delta.X),0),--use my gamepad delta to generate the angle
LerpFactor--use lerp to only go a percentage of that angle and not the whole thing
)
LastCF = Offset--unused
return Offset--return this offset for the main script to add together with all the rest
end
I also have offsets for sprinting, firing, etc but I’m sure you can figure out all that stuff