I’ve decided to create a 3rd person shoot game. One of the big things with is is the motion of moving the character head/arms. However, I’d like the gun to be even with the cursor at all times. The issue I am running into however is that the gun seems to move corresponding to a 3d point in the world, as opposed to the mouses 2d point.
As can be seen in this gif, the gun moves slightly up and isn’t in line with the cursor when I approach another humanoid.
The code I’m using on the server side to achieve the raising of the arm is:
player.Character.Humanoid.AutoRotate = false
local yOffset = (arg1.Position.y-arg2.p.y)/90 -- default 100
local mag = (arg1.Position-arg2.p).magnitude/100 -- default 80
yOffset = yOffset/mag
local neck = arg1.Parent.Head.Neck
--neck.C0 = CFrame.new(0, .9, 0) * CFrame.fromEulerAnglesXYZ(-yOffset,0,0)
local arm = arg1.Parent.RightUpperArm:FindFirstChild("RightShoulder")
if arm ~= nil then
arm.C0 = CFrame.new(1, 0.5, 0, 0, 0, 1, -6.48200512e-007) * CFrame.fromEulerAnglesXYZ(yOffset, 0,85)
end
The client side code for this is:
local Character = currTool.Parent
local arm = Character.UpperTorso.Parent.RightUpperArm:FindFirstChild("RightShoulder")
originalRight = arm.C0
while true do
if currTool.Parent.className ~= "Model" then
break
end
remoteFolder.appearanceUpdate:FireServer(remotePasskey, "TurnGo", Character.UpperTorso, plrMouse.Hit)
wait()
end
I’ve tried finding something on the wiki that would show how to get a mouse object and use it. Unfortunately, I’m unsure of how to do this.
Would anyone be able to help me achieve a smoothly moving way to raise the players arm according to the locked cursor position?
I am using an r15 rig, and the mouse is locked in the center.
Thanks to all!