Hiya, I have been trying to make my players arm which is not a viewport be attached to the camera and behave like a viewport but not itself be a viewport. I don’t want to make a viewport at all so please do not suggest me to.
RightShoulder.C0 = CFrame.new(((HRP.CFrame*RightShoulderC0):ToObjectSpace(Camera.CFrame)).Position)*RightShoulderC0*CFrame.Angles(0,0,x)
LeftShoulder.C0 = LeftShoulderC0*CFrame.Angles(0,0,x):Inverse()*CFrame.new(0,-1,0)
With that code I am getting this:
As you see I am using :ToObjectSpace()
to get the distance between the arm and the camera and then attempting to attach the arm to the camera. But I am unable to as shown in the video. Currently I am doing it to only the right arm for simplicity sake.
Can anyone please help me figure it out? Thanks!
Full Code
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local RightShoulder = Character:FindFirstChild("Right Shoulder",true)
local LeftShoulder = Character:FindFirstChild("Left Shoulder",true)
local HRP = Character:WaitForChild("HumanoidRootPart")
local Hum = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local CamAngle = Vector2.new(0,0)
local RightShoulderC0:CFrame = RightShoulder.C0
local LeftShoulderC0:CFrame = LeftShoulder.C0
local function lerp(a,b,t)
return a + (b - a) * t
end
Hum.AutoRotate = false
local lasty = 0
local function Update(dt)
Camera.CameraType = Enum.CameraType.Scriptable
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
UIS.MouseIconEnabled = false
local whitelist = {"Left Arm","Right Arm"}
for i,v in pairs(Character:GetChildren()) do
if v:IsA("Accessory") then
local p = v:FindFirstChild("Handle")
if p then
p.LocalTransparencyModifier = 1
end
end
if not table.find(whitelist,v.Name) and v:IsA("BasePart") then
v.LocalTransparencyModifier = 1
end
end
local HeadCF = Head.CFrame
local HeadPCF = CFrame.new(Head.Position)
local RotX = CFrame.Angles(0,math.rad(CamAngle.X),0)
local RotY = CFrame.Angles(math.rad(CamAngle.Y),0,0)
local AngleCF = HeadPCF*RotX*RotY
local DirectionalCF = CFrame.new(AngleCF.Position,AngleCF:ToWorldSpace(CFrame.new(0,0,-1)).Position)
local x,y,_ = DirectionalCF:ToOrientation()
local HumDirection = HRP.CFrame:VectorToObjectSpace(HRP.Velocity)/16
local z = math.rad(HumDirection.X*2.5 + math.clamp((lasty-y)*20,-3,3))
local ZRot = CFrame.Angles(0,0,-math.clamp(z,-10,10)):Inverse()
lasty = y
local XYRot = CFrame.Angles(-x-math.rad(HumDirection.Z*2.5),-y,0):Inverse()
local FinalCF = HeadPCF*XYRot*ZRot
Camera.CFrame = Camera.CFrame:Lerp(FinalCF,dt*15)
-- Help me part.
RightShoulder.C0 = CFrame.new(((HRP.CFrame*RightShoulderC0):ToObjectSpace(Camera.CFrame)).Position)*RightShoulderC0*CFrame.Angles(0,0,x)
LeftShoulder.C0 = LeftShoulderC0*CFrame.Angles(0,0,x):Inverse()*CFrame.new(0,-1,0)
-- Help me part.
Camera.FieldOfView = lerp(Camera.FieldOfView,70 + (HRP.Velocity.Magnitude/16) * 5,dt*7.5)
local hrpx,hrpy,hrpz = HRP.CFrame:ToOrientation()
HRP.CFrame = CFrame.new(HRP.Position)*CFrame.Angles(hrpx,y,hrpz)
if UIS:IsKeyDown(Enum.KeyCode.LeftAlt) then
UIS.MouseBehavior = Enum.MouseBehavior.Default
UIS.MouseIconEnabled = true
end
end
RS:BindToRenderStep("UpdateCamera", Enum.RenderPriority.Camera.Value - 1, Update)
UIS.InputChanged:Connect(function(Input,GPE)
if Input.UserInputType == Enum.UserInputType.MouseMovement then
local Delta = UIS:GetMouseDelta()
local X = CamAngle.X - math.clamp(Delta.X/6,-10,10)
local Y = math.clamp(CamAngle.Y - Delta.Y/4,-89,89)
CamAngle = Vector2.new(X % 360,Y) * (UIS.MouseDeltaSensitivity)
end
end)