I’m making a third person shooter, and I’m wanting the arms to rotate with the camera whilst the player aims the gun. However, this happens:
The arms infintely rotate; their speed defined by the camera’s rotation.
There is the snippet of code below, which is executed each frame.
local x, y, z = Camera.CFrame:ToOrientation()
Player.Character.Torso['Right Shoulder'].C1 = Player.Character.Torso['Right Shoulder'].C1 * CFrame.Angles(0,0,math.rad(-x))
Player.Character.Torso['Left Shoulder'].C1 = Player.Character.Torso['Left Shoulder'].C1 * CFrame.Angles(0,0,math.rad(x))
Any help would be appreciated.
1 Like
This is because C1 has a rotation which is multiplied by another rotation causing infinite rotation.
I believe you can just use rotation plus position instead.
C1 = CFrame.Angles(0,0,math.rad(-x)) + C1.Position
When I use that equation, I end up turning into this abomination:
It does this no matter which axis I put the math.rad(-x)
in…
And here’s the line of code again just in case I’ve made an error:
Player.Character.Torso['Right Shoulder'].C1 = CFrame.Angles(0,0,math.rad(-x)) + Player.Character.Torso['Right Shoulder'].C1.p
elomala
(elomala)
July 26, 2022, 7:02pm
#4
Try referencing to this topic it might help:
Basically, I’m making an FPS game and what I want is to rotate the arms towards the camera
an example is that if I look down the arms and head would rotate down and look like this
[Screen Shot 2022-04-14 at 10.48.05 PM]
Scottifly
(Scottifly)
July 26, 2022, 7:24pm
#5
Try searching “aim gun to face mouse” in the Search bar up top. This has been answered in other posts.
I’ve looked before, and most of them use the same formulas I did, which if you can tell by the code I provided and the video, don’t work. Could you please link one that uses another method?
I’m guessing there’s an initial offset rotation to the arms.
Outside of the loop store it.
C1RotatationStore = C1.Rotation
Then add it on to the formula
C1 = CFrame.Angles(0,0,math.rad(-x))*C1RotatationStore+ C1.Position
Sorry but that isn’t working either, my character’s arms just stay still.