How could I make your arms and head follow your mouse up and down?

How you be holding with 2 hands

4 Likes

Hello im making something similar and i modified the Headstackk formula to make it work for the tool Handle.
I move arms only locally, so heres the “Move arms” piece of my local script:

run.RenderStepped:Connect(function()
	if equipped then
		Torso.Motor6D.C0 = CFrame.new(0, 0, 0) * CFrame.Angles(math.asin((mouse.Hit.p - mouse.Origin.p).unit.y), 0, 0)
	end
end)

For “Torso.Motor6D” i mean the motor6D of the tool handle, you can create it in server just typing:

local motor = Instance.new("Motor6D")
motor.Part0 = character.Torso
motor.Part1 = tool.Handle
motor.Parent = character.Torso

This formula works for my tool’s motor6D, but it needs to be modified to make it work for shoulders, and unluckily i dont know how to do that. So, can someone try to modify it? It will be very helpful!
Thanks in advance. :grinning:

1 Like

This is the video of the formula:

Im also following the Headstackk guide to animate with tools:

Thats very helpful, so thanks @Headstackk.

1 Like

Hello again guys, i finaly found a good way to close this topic!
I modified the formula, and now it works nicely for arms, but it doesnt for the tool, so i decided to modify the motor6D of the toolHandle, so that the Part0 is now the RightArm.
Now, with this new motor6D, your tool will be attached at your arm, that follows the mouse, so, arms, and tool follow the mouse now!
This is a pretty easy way to animate too! You will not find yourself in difficulty with animating, trust me!

So, how did i modify the formula?
I saw that with the normal formula, the arm turned for itself, and it was because, the formula added in loop the angle that was needed for the arm to turn towards the mouse:

Torso["Right Shoulder"].C0 = Torso["Right Shoulder"].C0 * CFrame.Angles(math.asin((mouse.Hit.p - mouse.Origin.p).unit.y), 0, 0)

therefore it can be understood that by always adding the same angle, the arm turns on itself. So I had an idea, first of all i got the angles of “Torso[“Right Shoulder”].C0” just by doing “local rightX, rightY, rightZ = self.char.Torso[“Right Shoulder”].C0:ToEulerAnglesYXZ()”, then i took this: “Torso[“Right Shoulder”].C0” and i substracted the negative Z angle that i took from the :ToEulerAnglesYXZ() function.
Then i put this micro formula in brackets, and i added the new angles of the mouse.
Sorry, im not very good for explaining, specialy in english, so i will give you the finished formula:

run.RenderStepped:Connect(function()
	if equipped then
		local rightX, rightY, rightZ = self.char.Torso["Right Shoulder"].C0:ToEulerAnglesYXZ()
		self.char.Torso["Right Shoulder"].C0 = (self.char.Torso["Right Shoulder"].C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((self.mouse.Hit.p - self.mouse.Origin.p).unit.y))
		
		local leftX, leftY, leftZ = self.char.Torso["Left Shoulder"].C0:ToEulerAnglesYXZ()
		self.char.Torso["Left Shoulder"].C0 = (self.char.Torso["Left Shoulder"].C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((-self.mouse.Hit.p - -self.mouse.Origin.p).unit.y))
	end
end)

Here’s a video of how it should work:

I hope this was helpful for you guys! :grinning:

EDIT:
After 3 years, i wanted to thank you all for supporting this reply so much! I wrote this when i didn’t have much experience, and once i found the working formula, i just posted it here. So before just taking for granted, check out the problem yourself and try to find a better way to do it, just take this as a start.
Unfortunately, i won’t be answering anything anymore since i stopped being an active developer on roblox. Thanks again!

69 Likes

Sorry to bother everyone I don’t mean to revive this thread how ever I have done everything exactly as you have in the tutorial and I used your formula for arms and used render stepped and binded the Motor6D to the torso however I get this…

https://gyazo.com/9cfc52e8076efcaaa043068f8c86315b

The only way I can fix this is by binding the motor6D to the right arm and deleting the formula for the gun up/down however I now can’t animate the right arm independent of the gun which is what I wanted :confused:

Sorry, I think the formula up there is wrong, it should be:
Torso.Motor6D.C0 = CFrame.new(0,0,0) * CFrame.Angles(math.asin((mouse.Hit.p - mouse.Origin.p).unit.y), 0, 0)

1 Like

Ah yes it does indeed work however the gun moves forward/backwards along the arms when pointing up and down as you can see below.

https://gyazo.com/cef885a35e855f8c0a9d2dae1e0216c9

I am not sure how I would make it stay static and not move forwards/backwards along the players arms while moving up/down. Ill think I might just have to stick to welding it to the right arm as it looks more realistic.

My bad again, it should be Right Shoulder c0 * CFangles (0, math.pi/2) * offset, try to get the offset by yourself atm, I’m on mobile and I can’t get the code here right now. If this doesn’t work I’ll copy the code from my PC to here soon.

2 Likes
local rightX, rightY, rightZ = player.Character.Torso["Right Shoulder"].C0:ToEulerAnglesYXZ()
player.Character.Torso.ToolGrip.C0 = player.Character.Torso["Right Shoulder"].c0 * CFrame.Angles(0, 0, rightZ) * CFrame.Angles(0, 0, math.asin((-mouse.Hit.p - -mouse.Origin.p).unit.y))

https://gyazo.com/42eeb128b511f4e8997f00204cc96748

I tried this not sure if exactly the right way you said to do it but it works!!! Except it’s offset the gun towards the left arm and rotated it upside down so I had to rotate the handle in the model to get it to be right way up.

Here’s mine:
char.Torso.ToolGrip.C0 = char.Torso["Right Shoulder"].C0 * CFrame.fromEulerAnglesXYZ(0, math.pi/-2,0) * CFrame.new(-1,-0.5,0)
Alternatively:
char.Torso.ToolGrip.C0 = CFnew(ViewModel.Torso["Right Shoulder"].C0.Position) * CFnew(-1,-0.5,0)

8 Likes

Hello, sorry for bumping an old topic, but how can I do this, when my torso is rotated 45 degrees? Using the code mentioned before, the weapon moves up and down but with a curve.

2 Likes

Can you give us the full script please, because I am confused. Thanks

5 Likes

When the tool is equipped, run a looped animation of the hold pose.

there’s open source scripts to do with the head following the mouse thats both r6/r15 compatible on one of the roblox templates…check it out then modify the code it is really easy

I think this is solved because nobody is posting.

I still dont get this
i need this for my game

Yo i am confused too because i am trying to make the same thing but i don’t understand what i nead to do in your script to make it work! here what i am in your script!:


also here is the error

nvm i found out how to do it lol

Hi sorry to bump this topic but I’m using this code for the arms:

        local rightX, rightY, rightZ = char.Torso["Right Shoulder"].C0:ToEulerAnglesYXZ()
		char.Torso["Right Shoulder"].C0 = (char.Torso["Right Shoulder"].C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((mouse.Hit.p - mouse.Origin.p).unit.y))

		local leftX, leftY, leftZ = char.Torso["Left Shoulder"].C0:ToEulerAnglesYXZ()
		char.Torso["Left Shoulder"].C0 = (char.Torso["Left Shoulder"].C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((-mouse.Hit.p - -mouse.Origin.p).unit.y))

But when I go into first person the arms start moving closer/away from the camera:

Does anyone know how I can fix this?

Edit:
I also used this but it acts the same way:

        char.Torso["Right Shoulder"].C0 = CFrame.new(1,0.5,0) * CFrame.Angles(-math.asin((mouse.Origin.p - mouse.Hit.p).unit.y),1.55,0)
		char.Torso["Left Shoulder"].C0 = CFrame.new(-1,0.5,0) * CFrame.Angles(-math.asin((mouse.Origin.p - mouse.Hit.p).unit.y),-1.55,0)
1 Like