-
What do you want to achieve?
I have a shooting animation for a shotgun in my game. The animation itself works to the level its intended to, but it has one issue I can’t seem to be able to solve. -
What is the issue?
The part of the shotgun you are intended to pull back/downward, never moves correctly relative to the actual shotgun, which is an anchored model that works as an anchored viewmodel.
Example video of the current results:
-
What solutions have you tried so far?
Multiple different methods of moving it down locally, via CFrames and such. None have particularly seemed to work either.
Relevant functions:
local function tweenGunOffset(targetCFrame)
repeat gunOffset = gunOffset:Lerp(targetCFrame,0.25) task.wait(0.1) until (CFrameToOrientation(gunOffset)-CFrameToOrientation(targetCFrame)).Magnitude <= 0.1
end
local function shootGun()
if shootDebounce then return end; shootDebounce = true
local oldWalkSpeed = humanoid.WalkSpeed; humanoid.WalkSpeed = 0
tweenGunOffset(CFrame.Angles(0, 180, 6.175))
camera.CameraType, footstepSound.PlaybackSpeed, footstepSound.TimePosition = Enum.CameraType.Scriptable, 0.05, 0.15; footstepSound:Play()
tweenGunOffset(CFrame.new(0, 0, 0.75) * CFrame.Angles(0, 185.4, 6.15))
blackFrame.Visible = true; task.wait(0.25); blackFrame.Visible = false
tweenGunOffset(CFrame.new(0, 0, 2) * CFrame.Angles(0, 185.4, 4.4))
local targetRackOffset; repeat
targetRackOffset = CFrame.new(viewModelRack.CFrame:VectorToObjectSpace(-rackOffset))
viewModelRack.CFrame = viewModelRack.CFrame:Lerp(targetRackOffset,0.25)
task.wait(0.1)
until (viewModelRack.CFrame.Position-targetRackOffset.Position).Magnitude <= 0.1
task.wait(math.random(3,10) * 0.1)
repeat
targetRackOffset = CFrame.new(viewModelRack.CFrame:VectorToObjectSpace(rackOffset))
viewModelRack.CFrame = viewModelRack.CFrame:Lerp(targetRackOffset,0.25)
task.wait(0.1)
until (viewModelRack.CFrame.Position-targetRackOffset.Position).Magnitude <= 0.1
tweenGunOffset(CFrame.Angles(0, 180, 0))
camera.CameraType, humanoid.WalkSpeed, shootDebounce = Enum.CameraType.Fixed, oldWalkSpeed, false
end