-
What do you want to achieve?
I wanted to add viewmodel bopping into my game, and I found a forum post and implemented into the game.
Forum post I used:
-
What is the issue?
Sometimes the viewmodel decides to go underneath the baseplate, nowhere near the player. And in the roblox player, the viewmodel bopping is greatly exaggerated.
How it looks in studio:
robloxapp-20231027-2059073.wmv (1.6 MB)
How it looks in the roblox player:
robloxapp-20231027-2100431.wmv (2.0 MB)
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried changing some of the values. I don’t know any other viewmodel scripts that would work for my model.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local PlayerEvents = ReplicatedStorage:WaitForChild("PlayerEvents")
local LookUpDown = PlayerEvents:WaitForChild("LookUpDown")
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local Arms = ReplicatedStorage:WaitForChild("FirstPersonArms"):Clone()
Arms.Humanoid.PlatformStand = true
Arms.Parent = Player
local ClientModules = ReplicatedStorage:WaitForChild("ClientModules")
local SpringModule = require(ClientModules:WaitForChild("SpringModule"))
local primaryPart: Part = nil
local humanoid: Humanoid = nil
local runDebounce = false
local cameraOffset = CFrame.new(0, -1, 1.5)
local swaySpring = SpringModule.new()
local bobSpring = SpringModule.new()
local function Bob(addition)
return math.sin(tick() * addition * 1.3) * 0.25
end
local function update()
if runDebounce then
return
end
runDebounce = true
LookUpDown:FireServer(mouse.Hit.Position, Camera.CFrame.Position)
task.wait(.1)
runDebounce = false
end
local function setArmsToCam(dt: number)
if not primaryPart then
return
end
local Delta = UserInputService:GetMouseDelta()
swaySpring:shove(Vector3.new(-Delta.X/500, Delta.Y/500, 0))
bobSpring:shove(Vector3.new(Bob(3), Bob(6), Bob(3)) / 12 * (primaryPart.Velocity.Magnitude) / 12)
local UpdatedSway = swaySpring:update(dt)
local UpdatedBob = bobSpring:update(dt)
local cameraCframe = (Camera.CFrame*cameraOffset)
Arms:SetPrimaryPartCFrame(cameraCframe*
CFrame.new(UpdatedSway.X, UpdatedSway.Y, 0)*
CFrame.new(UpdatedBob.X, UpdatedBob.Y, 0)
)
end
local function charAdded(char: Model)
Arms.Parent = Camera
update()
humanoid = char:WaitForChild("Humanoid")
primaryPart = char.PrimaryPart
local lookConnection = Camera:GetPropertyChangedSignal("CFrame"):Connect(update)
humanoid.Died:Connect(function()
lookConnection:Disconnect()
Arms.Parent = Player
end)
end
if Player.Character then
charAdded(Player.Character)
end
Player.CharacterAdded:Connect(charAdded)
RunService.RenderStepped:Connect(setArmsToCam)
Here is the viewmodel that I’m using:
fpa.obj (16.4 KB)