Well you could do that, but now you have random things cramped inside 1 folder and also sometimes you want to ignore everything inside something except for 1 thing.
So I’d prefer just making a simple mouse module. It’s a very flexible option.
Well you could do that, but now you have random things cramped inside 1 folder and also sometimes you want to ignore everything inside something except for 1 thing.
So I’d prefer just making a simple mouse module. It’s a very flexible option.
please make uncopylocked place im suffering with all error and mess
Can you reply with the Spring Module script I can’t open that file type in studio or any other program
-- Constants
local ITERATIONS = 8
local Spring = {}
Spring.__index = Spring
function Spring.new(self, mass, force, damping, speed)
local spring = setmetatable({
Target = Vector3.new();
Position = Vector3.new();
Velocity = Vector3.new();
Mass = mass or 5;
Force = force or 50;
Damping = damping or 4;
Speed = speed or 4;
}, Spring)
return spring
end
function Spring.getstats(self)
return self.Mass, self.Force, self.Damping, self.Speed
end
function Spring.changestats(self, mass, force, damping, speed)
self.Mass = mass or self.Mass
self.Force = force or self.Force
self.Damping = damping or self.Damping
self.Speed = speed or self.Speed
end
function Spring.shove(self, force)
local x, y, z = force.X, force.Y, force.Z
if x ~= x or x == math.huge or x == -math.huge then
x = 0
end
if y ~= y or y == math.huge or y == -math.huge then
y = 0
end
if z ~= z or z == math.huge or z == -math.huge then
z = 0
end
self.Velocity = self.Velocity + Vector3.new(x, y, z)
end
function Spring.update(self, dt)
local scaledDeltaTime = dt * self.Speed / ITERATIONS
for i = 1, ITERATIONS do
local iterationForce= self.Target - self.Position
local acceleration = (iterationForce * self.Force) / self.Mass
acceleration = acceleration - self.Velocity * self.Damping
self.Velocity = self.Velocity + acceleration * scaledDeltaTime
self.Position = self.Position + self.Velocity * scaledDeltaTime
end
return self.Position
end
return Spring
wow, that’s was actually realy useful dude, but, can you please make a third part of the tutorial? on the gun swap and reloading?, that would be amazing, but good work bro, you helped a lot of ppl
keep getting this error
code
local function GetBobbing(addition)
return math.sin(tick() * addition * 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)
local UpdatedRecoilSpring = RecoilSpring:update(dt)
local UpdatedSwaySpring = RecoilSpring:update(dt)
local UpdatedBobbleSpring = RecoilSpring: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
This error occurs when your player doesn’t load in fast enough. You can counter this by just adding
:WaitForChild()
.
i added a wait for child but is this supposed to happen?
https://gyazo.com/23f855c8d38b02a1c656ceffa5488d35
I think that is a recoil related issue, not sure though. It looks like one. If the :WaitForChild()
is causing the issue then at the start of your code you can add if not game:IsLoaded() then game.Loaded:Wait() end
.
it is a recoil issue i think but how can it? i added the code that you wrote tho
Double check the local handler. It might be issues with shoving.
coroutine.wrap(function()
wait(0.2)
recoilspring:shove(Vector3.new(-2.8,math.random(-1,1),-10))
end)()
game:GetService("RunService").Heartbeat:Connect(function(dt)
if IsPlayerHoldingMouse then
if canfire then
canfire = false
recoilspring:shove(Vector3.new(3, math.random(-2,2),10))
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)()
double checkec already doesnt seem to be anything misplaced
for some reason the bullets appear as normal parts?
function module.cast(gun , endpos , 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.Color = Color3.new(219,239,0)
bullet.Material = Enum.Material.Neon
bullet.Parent = workspace
bullet.CFrame = CFrame.new(GunBarrel.Position , endpos)
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
Sorry if i am disturbing but can you help me with my past replies? My gun system has been stuck on that
EDIT
Alright I got some last min questions to ask
The sight is like sideways and stuff I tried setting the orientation but it gets close but I can’t get it any closer to where I want
If we wanted to make double guns would we have to make another local script?
Also I want to send a reloading function that I made but as I am not on my pc rn it ain’t possible
tip: apparently doing for _, v in pairs (or something like that) is quite expensive in fps, since thats how my old game did it and it was extremely laggy when firing for long periods of time, instead just call :emit directly on the particle emmitters, that should help with optimization
One question, how would i disable or turn off the viewmodel?
nevermind found a solution poggers
Hey i just have a little question i will use your thing because it’s looking cool but not for a viewmodel but for my gun (3rd person) and i got an error that i don’t understand (i wont show all the script but here a little part
local camoffset = CFrame.new()
local Modulespring = require(game.ReplicatedStorage.SpringModule)
local spring = Modulespring:new()
local camera = game.Workspace.Camera
local RunService = game:GetService("RunService")
while wait() do
if script.Parent.Parent == plr.Character and not isCooldown then
if isDown then
isCooldown = true
onBulletShot:FireServer(mouse.Hit, mouse.Target)
wait(timePerBullet)
isCooldown = false
local newoffset = CFrame.Angles(spring.p.x,0,0)
camera.CFrame = camera.CFrame * camoffset:Inverse() * newoffset
camoffset = newoffset
end
end
end
and here the error