How to point with you arm to your exact mouse position?

Hey guys! I hope you all do well, I’m trying to make a vote system like “Breaking Point” where you point with your arm and then you vote for a person to get killed, but I got a problem, when I try to script the “point your arm to mouse”, it doesn’t works as respected. The arm doesn’t points to where It’s the mouse exactly.

I tried doing it with a Tool, but it isn’t the same.

Here’s the screenshots:

image

image

As you can see my arm goes more down than to the left, and I don’t know how to fix this problem.

I’ll appreciate a lot your help and you if you can give me a hand with this, thank you so much for reading and bye bye, have a nice day!

  • LocalScript:
local RunService = game:GetService("RunService")



local Player = game.Players.LocalPlayer

local PlayerMouse = Player:GetMouse()



local Camera = workspace.CurrentCamera



local Character = Player.Character or Player.CharacterAdded:Wait()

local Head = Character:WaitForChild("Head")

local Neck = Head:WaitForChild("Neck")



local Arm = Character:WaitForChild("RightUpperArm")

local Shoulder = Arm:WaitForChild("RightShoulder")



local Humanoid = Character:WaitForChild("Humanoid")

local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")



local NeckOriginC0 = Neck.C0

local ShoulderOriginC0 = Shoulder.C0



Neck.MaxVelocity = 1/3



RunService.RenderStepped:Connect(function()

	local CameraCFrame = Camera.CoordinateFrame



	if Character:FindFirstChild("UpperTorso") and Character:FindFirstChild("Head") then

		local ArmLookVector = Arm.CFrame.lookVector

		local HeadPosition = Head.CFrame.p



		if Neck and Shoulder then

			if Camera.CameraSubject:IsDescendantOf(Character) or Camera.CameraSubject:IsDescendantOf(Player) then

				local Point = PlayerMouse.Hit.p



				local Distance = (Head.CFrame.p - Point).magnitude

				local Difference = Head.CFrame.Y - Point.Y



				Neck.C0 = Neck.C0:lerp(NeckOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance) ), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)

				Shoulder.C0 = Shoulder.C0:lerp(ShoulderOriginC0 * CFrame.Angles(-(math.asin(Difference / Distance)), (((HeadPosition - Point).Unit):Cross(ArmLookVector)).Y, 0), .5 / 2)

			end

		end

	end	

end)


Ok so this problem might end up being a little bit more demanding than you think it is. Only way you can do this accurately is with something called IK animations. Its a dynamic way of animating a part with multiple joints so they line up naturally.
Video here:

Devforum tutorial here:

(And honestly, it’s a pain in the ass to make yourself and there are a lot of modules made by other programmers that you can use lol)

3 Likes

I don’t find any that works like I want to, so I have to make it, but thanks!

1 Like

There isn’t something that I can do to make it? I am an intermedium class scripter, I even don’t have the math requirements to do this, I’m gonna try to learn them, but I don’t understand what are they doing in the code lines that are in his script, what would you recommend to me to do in this situation with your experience? Thanks.

To be honest the math requirement is not super super high (probably grade 10 or 11 highschool). And even then it’s just some trig. Egomoose made a tutorial on how it works (another roblox developer) and I found it super helpful. It’s 21 minutes long but if you watch the whole thing and understand/take notes you will get it pretty quick. Not much else I can really help with except maybe keep looking for an open source IK module that can fit your needs?

1 Like