Im trying to make a gun system; i cant find any dev forum posts or youtube tutorials about how to make what im trying to do
I have a viewmodel that has an animated CamPart; i’d like the campart rotations to play on the camera
this is what I have right now
(really messy code)
local GoalCFrame
-- renderstep loop below
local CamPart = Character.CamPart
local cameraX, cameraY, cameraZ = Camera.CFrame:ToOrientation()
local LastCFrame
local NEWCFRAME
local cp = Character.CamPart
local x,y,z = cp.CFrame:ToOrientation()
local hrpX,hrpY,hrpZ = Character.HumanoidRootPart.CFrame:ToOrientation()
x -= hrpX ; y -= hrpY ; z -= hrpZ
if LastCFrame then
x -= LastCFrame.X ; y -= LastCFrame.Y ; z -= LastCFrame.Z
end
if not GoalCFrame then
GoalCFrame = Vector3.new(x,y,z)
end
--LastCFrame = CFrame.Angles(math.rad(Vector3.new(Camera.CFrame:ToEulerAnglesXYZ()).X + CamPart.CFrame.Rotation.X), math.rad(Vector3.new(Camera.CFrame:ToEulerAnglesXYZ()).Y + CamPart.Rotation.Y), math.rad(Vector3.new(Camera.CFrame:ToEulerAnglesXYZ()).Z + CamPart.Rotation.Z))
--local GoalCFrame = Vector3.new(cameraX + x, cameraY + y, cameraZ + z)
--Camera.CFrame = Camera.CFrame * CFrame.Angles(math.rad(Vector3.new(Camera.CFrame:ToEulerAnglesXYZ()).X + CameraPart.CFrame.Rotation.X), math.rad(Vector3.new(Camera.CFrame:ToEulerAnglesXYZ()).Y + CameraPart.Rotation.Y), math.rad(Vector3.new(Camera.CFrame:ToEulerAnglesXYZ()).Z + CameraPart.Rotation.Z))
Camera.CFrame = Camera.CFrame * CFrame.Angles( math.rad(GoalCFrame.X ), math.rad(GoalCFrame.Y ), math.rad(GoalCFrame.Z) )
GoalCFrame = Vector3.new(x,y,z) - Vector3.new(Camera.CFrame:ToOrientation())
LastCFrame = Vector3.new(x,y,z)
print(x,y,z, GoalCFrame)
it half works, the inspect animation moves the camera according to the CamParts rotation - but it locks the camera into one direction
Let me know if this needs more explaining or if somethings confusing
for example what im trying to achieve: the campart is moved by an animation played on the character, i want the rotation on the campart played from the animation copied to the players camera
so if the players camera cframe was 0,0,0 and the CamPart’s rotation was 0,50,0 then i’d want the camera Cframe to be 0,50,0; same thing for if the players camera cframe was 10,90,50 and campart was 40,40,40 then i’d want the camera’s cframe to be 50,140,90
I cant find a way for the camera to not overadd the cameraparts cframe, it always ends up adding the same calcuation over and over or doubling it
any help appreciated