Mainmodule:
local module = {}
local function GetBobbing(addition)
return math.sin(tick() * 1.3) * 0.5
end
function module.update(viewmodel, dt, RecoilSpring, BobbleSpring, SwayingSpring)
viewmodel.HumanoidRootPart.CFrame = game.Workspace.Camera.CFrame
local Bobble = Vector3.new(GetBobbing(10), GetBobbing(5), GetBobbing(5))
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
BobbleSpring:shove(Bobble / 10 * (Character.HumanoidRootPart.Velocity.Magnitude) / 10)
-- // BobbleSpring:shove(Bobble / 10 * (Character:WaitForChild("HumanoidRootPart").Velocity.Magnitude) / 10)
local UpdatedRecoilSpring = RecoilSpring:update(dt)
local UpdatedBobbleSpring = BobbleSpring:update(dt)
local UpdatedSwayingSpring = SwayingSpring:update(dt)
viewmodel.HumanoidRootPart.CFrame = viewmodel.HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(UpdatedBobbleSpring.Y, UpdatedBobbleSpring.X, 0))
viewmodel.HumanoidRootPart.CFrame *= CFrame.Angles(math.rad(UpdatedRecoilSpring.X) * 2, 0, 0)
game.Workspace.Camera.CFrame *= CFrame.Angles(math.rad(UpdatedRecoilSpring.X), math.rad(UpdatedRecoilSpring.Y), math.rad(UpdatedRecoilSpring.Z))
end
function module.weldgun(gun)
local Main = gun.GunComponents.Handle
for i, v in ipairs(gun:GetDescendants()) do
if v:IsA("BasePart") and v ~= Main then
local NewMotor = Instance.new("Motor6D")
NewMotor.Name = v.Name
NewMotor.Part0 = Main
NewMotor.Part1 = v
NewMotor.C0 = NewMotor.Part0.CFrame:inverse() * NewMotor.Part1.CFrame
NewMotor.Parent = Main
end
end
end
function module.equip(viewmodel, gun, hold)
local GunHandle = gun.GunComponents.Handle
local HRP_Motor6D = viewmodel:WaitForChild("HumanoidRootPart").Handle
gun.Parent = viewmodel
HRP_Motor6D.Part1 = GunHandle
local Hold = viewmodel.AnimationController:LoadAnimation(hold)
Hold:Play()
end
function module.cast(gun, endposition, velocity)
local gunBarrel = gun.GunComponents.Barrel
local Bullet = Instance.new("Part")
Bullet.Size = Vector3.new(1, 1, 5)
Bullet.Anchored = true
Bullet.CanCollide = false
Bullet.BrickColor = BrickColor.White()
Bullet.Material = Enum.Material.Neon
Bullet.Parent = game.Workspace
Bullet.CFrame = CFrame.new(gunBarrel.Position, endposition)
local Loop
Loop = game:GetService("RunService").RenderStepped:Connect(function(dt)
Bullet.CFrame *= CFrame.new(0, 0, -velocity * (dt * 60))
if (Bullet.Position - gunBarrel.Position).magnitude > 5000 then
Bullet:Destroy()
Loop:Disconnect()
end
end)
end
return module
LocalHandler:
local GunModel = game.ReplicatedStorage:WaitForChild("Groza") -- your gun
local Viewmodel = game.ReplicatedStorage:WaitForChild("Viewmodel") -- the viewmodel!!
local IsPlayerHoldingMouse
local CanFire = true
local Delay = 0.1
local AnimationsFolder = game.ReplicatedStorage:WaitForChild("Groza_Animations")
-- our mainmodule
local MainModule = require(game.ReplicatedStorage.MainModule)
local SpringModule = require(game.ReplicatedStorage.SpringModule)
local RecoilSpring = SpringModule.new()
local BobbleSpring = SpringModule.new()
local SwayingSpring = SpringModule.new()
Viewmodel.Parent = game.Workspace.Camera
-- alright first lets position the viewmodel
MainModule.weldgun(GunModel)
--//MainModule.equip(Viewmodel, GunModel)
game:GetService("RunService").RenderStepped:Connect(function(dt)
MainModule.update(Viewmodel, dt, RecoilSpring, BobbleSpring, SwayingSpring)
end)
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
IsPlayerHoldingMouse = true
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
IsPlayerHoldingMouse = false
end
end)
game:GetService("RunService").Heartbeat:Connect(function(dt)
if IsPlayerHoldingMouse then
if CanFire then
CanFire = false
RecoilSpring:shove(Vector3.new(1, 0, 0))
MainModule.cast(GunModel, game.Players.LocalPlayer:GetMouse().Hit.Position, 60)
wait(Delay)
CanFire = true
RecoilSpring:shove(Vector3.new(3, math.random(-2, 2), 10)) -- Vector3.new(up, sideways, shake)
coroutine.wrap(function()
for i, v in pairs(GunModel.GunComponents.Barrel:GetChildren()) do
if v:IsA("ParticleEmitter") then
v:Emit()
end
end
local FireSound = GunModel.GunComponents.Sounds.Fire:Clone()
FireSound.Parent = game.Workspace
FireSound.Parent = nil
FireSound:Destroy()
end)()
coroutine.wrap(function()
wait(0.2)
RecoilSpring:shove(Vector3.new(-2.8, math.random(-1, 1), -10))
end)()
end
end
end)
MainModule.equip(Viewmodel, GunModel, AnimationsFolder.HoldAnimation)