I’m trying to get a viewmodel system like criminality, It moves freely and stops going up at a certain point. However when I tried to do this (and I’ve been trying for like 2 hours), it never works as intended.
I’ve recently gotten pretty close actually, however another error emerges.
-- Pivot the arms to the camera, targetCFrame is the offset plus movement sway, swayCFrame is left and right sway
viewmodel:PivotTo(camera.CFrame * (targetCFrame * swayCFrame))
ArmHeight() -- calling my function to make the arms not go too high
function ArmHeight()
local target = hrp.CFrame.Position.Y -- HumanoidRootPart point,
local actual = viewmodel.ArmPos.CFrame.Position.Y -- ViewModel highest arm point
if tonumber(actual) > tonumber(target) then
viewmodel:PivotTo(CFrame.new(viewmodel.PrimaryPart.CFrame.Position.X, hrp.CFrame.Position.Y + 1, viewmodel.PrimaryPart.CFrame.Position.Z))
end
end
The problem is it’s locking up in a certain direction, I’m sure whatever I’m doing wrong is obvious but I’m just not seeing it, Video of what’s happening :
local MaxUpRotation = 20 -- change to your likings
local targetcframe = workspace.CurrentCamera.CFrame
local Pitch,_,_ = targetcframe:ToOrientation()
Pitch = math.min(Pitch,math.rad(MaxUpRotation))
viewmodel.CFrame = torso.CFrame * CFrame.Angles(Pitch,0,0)
This doesn’t work, and even after I fixed it it’s just not what I’m looking for.
You see, what I’m trying to replicate is a regular viewmodel, except it stops going up with my camera past a point.
If I look straight, my arms are pointed straight. if I look down, they point down, but if I look up, I want them still pointed straight. That’s exactly how criminality has it, the running animation is the same looking straight as looking down, but if you look up then your arms stop going up.
I should probably elaborate, it doesn’t work because viewmodel is a model, and as such does not have a CFrame. if I do the primary part CFrame, the arms along with it just fly off into the distance, how I fixed it is using the same :PivotTo
This just makes the arms a certain height (which technically is what I want, it’s just not moving around at all.). Aswell as the sway being buggy, but I’m sure that’s fixable.
This is how I had to modify the script to get it working.
function ArmHeight()
local MaxUpRotation = 5 -- change to your likings (did nothing, 5 and 20 still the same)
local targetcframe = workspace.CurrentCamera.CFrame
local Pitch,_,_ = targetcframe:ToOrientation()
Pitch = math.min(Pitch,math.rad(MaxUpRotation))
local newpos = CFrame.new()
newpos = newpos * hrp.CFrame * CFrame.Angles(Pitch,0,0)
viewmodel:PivotTo(newpos)
end
I’m going to assume that my “fix” to the script just broke it. I’ll also provide a video of what happens if I use your script except I change the primarypart CFrame.
function ArmHeight()
local MaxUpRotation = 5 -- change to your likings (did nothing, 5 and 20 still the same)
local targetcframe = workspace.CurrentCamera.CFrame
local Pitch,_,_ = targetcframe:ToOrientation()
Pitch = math.min(Pitch,math.rad(MaxUpRotation))
local newpos = CFrame.new()
newpos = newpos * hrp.CFrame * CFrame.Angles(Pitch,0,0)
viewmodel:PivotTo(newpos)
end
In here, the hrp which was previously called torso (in the original script that i sent) MUST be the player character’s torso, and not the viewmodel’s
function ArmHeight()
local viewmodeloffset = Vector3.new(0,0,0) -- Change to whatever you want
local MaxUpRotation = 5 -- change to your likings (did nothing, 5 and 20 still the same)
local targetcframe = workspace.CurrentCamera.CFrame
local Pitch,_,_ = targetcframe:ToOrientation()
Pitch = math.min(Pitch,math.rad(MaxUpRotation))
local newpos = CFrame.new((hrp.CFrame * CFrame.Angles(Pitch,0,0))*CFrame.new(viewmodeloffset))
viewmodel:PivotTo(newpos)
end
Thank you, this is so close to the exact output I wanted, however the sway is now choppy, I again had to change your code a little bit, when you add CFrames it’s much easier to lerp from my experience, here’s the new code
function ArmHeight()
local viewmodeloffset = Vector3.new(0,0,0) -- Change to whatever you want
local MaxUpRotation = 5 -- change to your likings (did nothing, 5 and 20 still the same)
local targetcframe = workspace.CurrentCamera.CFrame
local Pitch,_,_ = targetcframe:ToOrientation()
Pitch = math.min(Pitch,math.rad(MaxUpRotation))
local newpos = CFrame.new()
newpos = newpos:Lerp(hrp.CFrame * CFrame.Angles(Pitch,0,0)*CFrame.new(viewmodeloffset), 1)
viewmodel:PivotTo(newpos)
end
Video representation of the problem :
Thank you again, this is so close and if you don’t want to help me further I completely understand