Rotate part around X axis of a camera

I have 2 CFrames: one for the arm of a player, and one of the camera. I want to rotate the arm sorta parallel to the X rotational axis of the camera (the looking-up-and-down axis). I do not want it to match the camera CFrame/Orientation, but I want to offset it’s current CFrame by this camera-x-axis rotation. How would I do this?

2 Likes

It depends on whether you have an r6 or r15 rig, but the main concept is that you would translate your camera world CFrame into something relative to the player and then with that relative CFrame we are able to get the angle that we can use to put on our shoulder joint. It could look something like this. You would also have this in a loop so it updates every interval

local rootPart = character.HumanoidRootPart
local camera = workspace.CurrentCamera
local relative = rootPart.CFrame:ToObjectSpace(camera.CFrame)
local degree = math.asin(relative.LookVector.Y)
	
ShoulderJoint.C0 = CFrame.Angles(degree, 0, 0)

There is always some offset that the joint has automatically so I did not account for that if you can give me the rig you are using I can give you a script you can use

1 Like

Here is what I have (I am using an R15 rig):

        local newConnection = RunService.Stepped:Connect(function()
            leftShoulder.Transform = CFrame.Angles(LightAttack.CurrentLookAngle, 0, 0 ) * leftShoulder.Transform.Rotation + leftShoulder.Transform.Position
            rightShoulder.Transform =  CFrame.Angles(LightAttack.CurrentLookAngle, 0, 0 ) * rightShoulder.Transform.Rotation + rightShoulder.Transform.Position
        end)

This codes offsets the arms properly but it doesn’t angle it properly. You can see it sorta works but doesn’t take account for the Upper and Lower torso angles:

(this sorta works because I don’t move the torso much)


(this doesn’t work because the animation I’m playing affects the torso, look at what happens when I look straight down)

1 Like

I think most games modify the torso joint instead of the arm joint, this would avoid having to account for the accumulation since the torso is the root of all the other joints.

1 Like

honestly, i think if i were to attempt this today, i would try to rotate both the torso, head and the arms. imitating the attack directions irl i notice that my torso slightly adjusts to match the angle (but not completely!) and so does my head, so i think messing around with that type of procedural animation could maybe work okay. thats of course if the goal is to apply this to existing animations. if one was really ambitious, going all in on procedural animations could definitely work but it’d take i think a lot of effort to make it look good and more specifically, the way you’d want it to look (instead of adding personality through animating, scripting is needed instead which is both a bit harder but also a lot less documented than animation is).

actually now that i think about it, i shouldve probably looked into mordhau or any of those games that already have angle-able animations/attacks.

on a side note i noticed that in elden ring the player will slightly rotate upwards or downwards if the enemy is above or below, so if someone wanted a compromise, just having slightly angleable attacks would probably work ok (its at least better than nothing)

1 Like