In mostly all Roblox first-person shooters, when you look up with your camera, your arms and your gun also angle up. I have a custom inventory system where I just have an object welded to the player.
When I look up, obviously the object will just stay in the welded position, same as tools. So how could I make it go up too?
Weld the gun to the hand so that when you look up, the arm will angle up and therefore your hand will angle up and therefore the gun will change angles.
Attach it to the Camera. This way, no matter what angle the camera is facing, the object will stay in the same place relative to it.
No, when I look up, the arms don’t.
How do I detect the angle of the camera?
Camera objects have a CFrame property!
Ok so weld the gun to the hand and then every render step or so, set the CFrame of the arms like so:
local lookAtPosition --this can be the mouse's position
leftArm.CFrame = CFrame.new(leftArm.CFrame.Position,lookAtPosition)
rightArm.CFrame = CFrame.new(rightArm.CFrame.Position,lookAtPosition)
This CFrame constructor takes two vectors. The position for the CFrame, and where the CFrame should be facing. If you don’t understand how CFrames work, I suggest visiting EgoMoose’s tutorial on them.
Edit: If you’re looking to make a first-person shooter, you will need to set the LocalTransparencyModifier of the parts you want to make visible to 0.
Thanks so much! I didn’t even know the camera had Cframe!