How could I point an R15 rig's arm to the mouse' position?

I was thinking of writing something like that, but I think OP is talking about FPS arms, like the ones that hold a gun and are always pointing to the camera.

1 Like

On the client, make the character’s arms invisible and create new fake arms that line up where you want them to in first person.

1 Like

In that case, he’ll want to use a viewport model.

3 Likes

Another way instead of using a viewport is by creating two instances and making something to directly match the camera’s position but be a bit offset. I created a demo for something like this:

wait(1)
local Camera = workspace.CurrentCamera
local Arm1 = Instance.new("Part")
local Arm2 = Instance.new("Part")
function InitArm(Arm, Player, ArmType)
	if Arm and Player then
	if Arm:IsA("BasePart") and Player:IsA("Player") and Player.Character ~= nil then
		Arm.Size = Vector3.new(1,1,2)
		local ArmPart = ((Player.Character:FindFirstChild("Humanoid").RigType == Enum.HumanoidRigType.R6 and Player.Character:FindFirstChild(string.format("%s Arm", ArmType))) or (Player.Character:FindFirstChild("Humanoid").RigType == Enum.HumanoidRigType.R15 and Player.Character:FindFirstChild(string.format("%sHand", ArmType))))
		Arm.Color = ArmPart.Color
		Arm.CanCollide = false
		Arm.Anchored = true
		Arm.Position = Vector3.new()
		Arm.Parent = workspace
		game:GetService("RunService").RenderStepped:Connect(function()
			if ArmType == "Left" then
				Arm.CFrame = ((Camera.CFrame - (Camera.CFrame.RightVector / 1.25)) - (Camera.CFrame.UpVector / 1.25)) + (Camera.CFrame.LookVector * 1.25)
			else
				Arm.CFrame = ((Camera.CFrame + (Camera.CFrame.RightVector / 1.25)) - (Camera.CFrame.UpVector / 1.25)) + (Camera.CFrame.LookVector * 1.25)
			end
		end)
	else return error("Missing a key part");end
	else return error("Missing a key part");end
end
InitArm(Arm1, game.Players.LocalPlayer, "Left")
InitArm(Arm2, game.Players.LocalPlayer, "Right")

It gives the effect that you’d also get via viewport.

But yes, a viewport would most likely be the best solution for this type of thing.

5 Likes

Viewport works, but you’ll ultimately end up with worse quality aside from it just being completely redundant. @zQ86’s option is the optimal solution for placing arms on the camera.

3 Likes

In that case, how would you add constraints to make it more realistic without having to do the math? If the CFrame on the arms is being constantly updated and they’re anchored, they can’t be susceptible to constraints.

2 Likes

You could possibly lerp or tween the arms to get a smooth rotation, but at the same time the CFrame would have to be interrupted to proceed with that.

1 Like

What about having an idle animation play constantly? That way you could interrupt it with an overlay for actions such as shooting.

1 Like

Are you talking about AnimationControllers?

1 Like

If it’s an FPS, a Humanoid would work, but yes, essentially. You don’t need to go through the extra work of a custom system like this if you just have an idle animation.

2 Likes

You’re correct. Your viewport suggestion can be easily manipulated to make a simple animation script using CFrame logic, since the CFrame is not constantly updating.

1 Like

Yes, but as @Stratiz suggested, that would be lacking in quality. (not sure why, hopefully he’ll respond)

If he really wanted to do the work, it would require an IK system for animating as you’d need to account for the rig’s arms. A viewport model would be my solution as it could be changed any way you wanted.

2 Likes

I think the reason he says it lacks in quality is because it does not support lighting and looks like quality setting 1.

1 Like

It doesn’t support lighting quality? Maybe we’re thinking of a different type of viewport model. My idea is where arms are welded to a camera brick that is welded to the character’s camera CFrame in first person mode.

1 Like

Oh. I thought you were talking about a ViewportFrame. I think Stratiz thought you were talking about that, too. That can work, most definitely.

2 Likes

Here is a good example:

Within the FPS module there is this function

local function updateArm(self, key)
	if (self[key]) then
		local shoulder = self.isR15 and self.viewModel[key.."UpperArm"][key.."Shoulder"] or self.viewModel.Torso[key .. " Shoulder"];
		local cf = self.weapon[key].CFrame * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0, self.isR15 and 1.5 or 1, 0);
		shoulder.C1 = cf:inverse() * shoulder.Part0.CFrame * shoulder.C0;
	end
end

Sorry I’m not quite sure how to format code on here but this should help

4 Likes

Thanks guys! I’ll definitely read up on all your replies and toy around with this. Much appreciated. :slight_smile:

3 Likes

I think he’s confusing a view model in the Workspace or CurrentCamera (created by the client) for a ViewportFrame. Since the term viewport has been used interchangeably with ViewportFrames for whatever reason ever since the latter’s release, it’s been hard to distinguish what exactly one means when they say viewport.

View(port) models do not diminish quality or incur redundancy. It’s a model that’s created on the client. You’ll rarely have any real performance issues unless you’re making unwise choices with how you’re updating or setting up the model. Don’t worry about this.

2 Likes

Oh my apologies, I thought you were talking about a viewport frame. I should’ve read a little closer.

@colbert2677 Is correct, viewport models should be alright.

1 Like

Also you can check out this article i wrote. I may help answer this and a few other questions along the way.

8 Likes