What do you want to achieve? Keep it simple and clear!
Basicly I am wondering how i do the gun sway part. Any tips or ideas will work.
i am not asking for full scripts i am just wondering on how to and tips
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Solutions i have tried is not many either they will fling the character or so. I have been looking on here but all I find is something idk what they mean or wanna bind it to.
a lot of games use spring to accomplish gunsway, but you can also do it using sine waves:tm: and lerping between the last camera cframe to the current one, here’s a code snippet, comes with idle sway as a bonus just because it’s easier for me to keep it there than forking it out
local lastCF = cam.CFrame
local sway = CFrame.new()
local sinValue = 0
local lerp = 0
game:GetService("RunService").RenderStepped:Connect(function(dt)
local deltaRatio = deltaFramerate / (1 / dt) --//deltaFramerate is the framerate you want things to update in, 60 is usually a good pick
local function calculateSine(speed) --//for idle sway
sinValue += speed * deltaRatio
if sinValue > (math.pi * 2) then sinValue = 0 end
local sineY = 0.01 * math.sin(2 * sinValue)
local sineZ = 0.01 * math.sin(sinValue)
local sineCFrame = CFrame.new(sineZ, sineY, 0)
return sineCFrame
end
local swaymultiplier = 0.3 --//sway speed
local x, y, z = workspace.Camera.CFrame:toObjectSpace(lastCF):ToOrientation()
sway = sway:Lerp(CFrame.Angles(math.sin(x) * swaymultiplier,math.sin(y) * swaymultiplier, 0), 0.15) --//for gun sway
lerp -= 0.1 / aimTime * deltaRatio
if lerp < 0 then lerp = 0 end
local sineCFrame = calculateSine(0.04)
Weapon.Aim.CFrame = (cam.CFrame * restPosition * sineCFrame):lerp(cam.CFrame * aimPosition, lerp) * sway
lastCF = cam.CFrame
end)
this likely won’t be compatible with your current framework so you’ll have to do some adjustments
Ok so the veiwmodel CFrame is the primary part of the view model?
And the rest position is the same as where i the regular for CFrame is for the primarypart
I think it is possible watch Quake II gameplay and if they move the camera it looks like ID Software used weapon sway animations based on which way you move the camera (sorry for necrobump)