ViewModel in the context here being for an FPS game, where your gun follows where you're looking around. This is the current code that handles what I'm trying to achieve.
if InFirstPerson == false then while (Camera.Focus.p - Camera.CFrame.p).magnitude < 1 and WR.Value == 4 and Hlstrd == false do InFirstPerson = true Mouse.TargetFilter = workspace wait() game.Players.LocalPlayer.Character.Head.Neck.C0 = CFrame.new(0, .85, 0) * CFrame.Angles(math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y), 0, 0) end else end if (Camera.Focus.p - Camera.CFrame.p).magnitude > 1 or WR.Value ~= 4 or Hlstrd == true then InFirstPerson = false local Restoration = game.Players.LocalPlayer.Character.Head.Neck if Restoration.C0 ~= CFrame.new(0, .85, 0) * CFrame.fromEulerAnglesXYZ(0, 0, 0) then Restoration.C0 = CFrame.new(0, .85, 0) * CFrame.fromEulerAnglesXYZ(0, 0, 0) else end end
It spikes up at 2% in the LocalScript running it and only handles the head, as you can see... the attempt is being made on an R15 player model and doesn't replicate to the Server. I want to find the most efficient solution here to have the player's weapons follow their camera around under the circumstances in the scripting above.
WR is WeaponReadiness, 4 on this scale = Engaged, or "weapon raised". Hlstrd is just a shortened version of Holstered. You have to have the weapon in-hand.
As long as the weapon is in your hand, and you're in WR level 4 (engaged), the arms, and head will follow your camera around. If you have holstered your weapon, or lowered it to a more relaxed state, the ViewModel stops and waits to be turned on again. This increases overall performance. I want to have it include the UpperTorso when your player model is seated, for vehicle fun, IE: helicopter rides or riding in the back of a truck.
For extra information, the player has a modified camera script that only makes the head and any accessories on the player vanish in 1st Person as opposed to their entire body. This enhances immersion since you can look down and see your body. I figured that with this out of the way, there may be a way to just use the normal limbs to set up a ViewModel?
Any suggestions to get a high performance ViewModel set up?