Context:
I’ve been stuck on this issue for multiple hours now trying random different options to reach my goal without success despite looking for other posts on this website. This happens as i’m trying to add an arm rotation to my combat system (which is very similar to the one on “Mount & Blade”), and it is necessary to the system because the player has to be able to adjust the hits to any part of the opponent’s body he wants to be able to hit because there is an armor system based on the armor level on a specific body part.
The issue:
With a bit of research I’ve managed to do a simple arm rotation script which works partially as expected. The arms go up and down as they should based on the camera’s orientation. Here is an example:
In that example, it works as it should. However, the moment I hold left click (which basically “prepares” my attack until I release my LMB), when the torso is rotated due to the animation, the arms still go up and down but relative to the torso (which isn’t exactly what I want). The problem it causes is that whenever the player looks up or down, now it does something like this:
As you can see, it’s not very useful in order to be able to accurately adjust your hit (and this will especially be an issue with pikes/spears). Here is the expected behavior that I’ve manually reproduced:
The code:
rs.RenderStepped:Connect(function()
local camDir = char.Torso.CFrame:ToObjectSpace(camera.CFrame).LookVector
local headDir = char.Torso.CFrame:ToObjectSpace(char.Head.CFrame).LookVector
local rArmDir = char.Torso.CFrame:ToObjectSpace(char["Right Arm"].CFrame).LookVector
neck.C0 = neckOrigin * CFrame.Angles(0,0, -math.asin(headDir.X)) * CFrame.Angles(-math.asin(camDir.Y), 0, 0) * CFrame.Angles(0,0,math.asin(headDir.X))
rShoulder.C0 = rShoulderOrigin * CFrame.Angles(0,0,math.asin(camDir.Y))
lShoulder.C0 = lShoulderOrigin * CFrame.Angles(0,0,-math.asin(camDir.Y))
end)
Note:
Please, when formulating a response, start under the assumption that I cannot understand half of what you are saying when it’s math related (because it is likely going to be the case).
Does anyone have a solution to this problem?
Thanks for the help.