Changing CFrame of Motor6D Breaks Animation

I am trying to connect a weapon to the player’s right arm using Motor6D so I can animate the weapon.

However, when I do this, the joint gets created with the proper Part0, Part1 and parent, but the weapon moves undesirably.

Here is a video showcasing the issue:

As you can see, the weapon behaves very strangely. When the player is idle, the weapon moves far away and back to the hand repeatedly. With humanoid states like running and jumping, the weapon goes flying all over the place.

Here is what the idle animation is supposed to look like:

In the video you can see that the weapon is in the hand properly and not floating into the ground like it does in-game.

Here is also the script that connects the weapon to the player’s right arm:

local SS = game.ServerStorage
local classArsenals = SS.ClassArsenals

local used = false

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not used then
		used = true
		
		local character = hit.Parent
		local rightArm = character.RightArm
		
		local warriorArsenal = classArsenals.WarriorArsenal:Clone()
		local weapon = warriorArsenal.Weapon.Plastic
		
		local weaponJoint = Instance.new("Motor6D")
				
		weapon.CFrame = rightArm.CFrame * CFrame.new(0, -1.1, -1.35)
		weaponJoint.Part0 = rightArm
		weaponJoint.Part1 = weapon
		weaponJoint.C0 = rightArm.CFrame:Inverse()
		weaponJoint.C1 = weapon.CFrame:Inverse()
		weaponJoint.Parent = rightArm
		
		warriorArsenal.Parent = character
	end
end)

Something I have noticed is that when I take out the parts of the code involving setting the CFrame, C0 and C1 of the weapon and joint, the weapon works correctly in the animations. Of course without setting the CFrames though, the weapon is not positioned correctly and ends up in the middle of the player’s arm. This leads me to believe the problem is with the CFrames, but I cannot figure out how to fix it.

If you have any ideas on how I could fix this, do not hesitate to let me know!

2 Likes

When working with CFrames I have learned to assume two things can go wrong, either:

  1. Your CFrame rotations and positioning are wrong

  2. Most frustratingly your CFrame order of operations are wrong as shown in this scripting support where I faced a kinda similar issue of CFrames not working with motor6d.

Judging by the video of the idle animation what causes the issue is the inverse operation:

This inverse operation undoes the position of the right arm at the position of the world when you touched the brick and makes it so the right arm will go back to the origin at (0,0,0) which is what seems to be happening in the video. Plus the idle animation is still playing which is causing the transform operation of the motor6d to keep moving back and forth.

Honestly, the best solution I found is is to apply CFrame operations one by one and see if it achieves the desired effect.

For your case I recommend finding out the C0 and C1 positions of the motor which you used for your idle animation (print them out) which I believe have a constant position and orientation as they are relative to part0 and part1 respectively.

2 Likes