Trouble Manipulating Motor6Ds

Hello!

I am trying to make the character’s arms shake when it fires a weapon. I am doing this procedurally, so without key framed animations.

To accomplish the procedural side of things I made a custom procedural animation module a while back which has no bugs that could be introducing the problem at hand.

When manipulating the Motor6Ds to shake the arms using Motor6D.Transform it doesn’t actually do anything. Even worse, it seems to be changing the Motor6D.C0 to CFrame.new(). Why is it doing this and how do I fix it?

I’ve tried all the solutions I can think of, including doing away with the Motor6Ds altogether. Some solutions have worked, but because I want to work with other procedural elements on top of the arm shake, I couldn’t use those solutions since they were half measures. I’ve tried only using Motor6D.C0 But that seems to have just bugged the key framed animations.

	local Motor6Ds : M6DTable = {
		RightShoulder = AnimInst.PlayerData.Character.LeftUpperArm.LeftShoulder;
		LeftShoulder = AnimInst.PlayerData.Character.RightUpperArm.RightShoulder;
	}

	local LeftArmDefault = MovedArmRootCF:ToObjectSpace(Motor6Ds.LeftShoulder.Part1.CFrame)
	local RightArmDefault = MovedArmRootCF:ToObjectSpace(Motor6Ds.RightShoulder.Part1.CFrame)

	local function Update(dt:number)
		InterpCF = ShootProcedural:UpdateCFrame(TargetCF, Motor6Ds.LeftShoulder.C1, dt) -- My custom procedural animation module.

		if TarDistance > (TargetCF.Position - InterpCF.Position).Magnitude then
			TargetCF = CFrame.new()
		end
		
		
		MovedArmRootCF = OffsetCFByCF(Motor6Ds.LeftShoulder.Part0.CFrame, ArmRootCF.Value)
		local InterpArmRoot = OffsetCFByCF(InterpCF, MovedArmRootCF)
		
		for _, Motor6D:Motor6D in pairs(Motor6Ds) do
			Motor6D.C1 = CFrame.new()
		end
		
		Motor6Ds.LeftShoulder.Transform = Motor6Ds.LeftShoulder.Transform * (Motor6Ds.LeftShoulder.Part0.CFrame:ToObjectSpace(InterpArmRoot:ToWorldSpace(LeftArmDefault))) -- All this extra stuff after "Motor6Ds.RightShoulder.Transform" is just extra calculations to make sure all the limbs stay together and don't float around.
		Motor6Ds.RightShoulder.Transform = Motor6Ds.RightShoulder.Transform * (Motor6Ds.RightShoulder.Part0.CFrame:ToObjectSpace(InterpArmRoot:ToWorldSpace(RightArmDefault)))
    end

Here is an image of the failed transformations:

1 Like

Becouse originally limbs dont have CFrame.identity on C1 and there so you are ruining limb offsets by setting it to zero.

I fixed the offsets, so the limbs are remaining in the right place, but using the Transform property of the Motor6D still doesn’t do anything, there is no movement.

I checked to make sure the InterpCFrame is actually moving and it is.

		Motor6Ds.LeftShoulder.Transform = Motor6Ds.LeftShoulder.Transform * (Motor6Ds.LeftShoulder.Part0.CFrame:ToObjectSpace(InterpArmRoot:ToWorldSpace(LeftArmDefault)))
		Motor6Ds.RightShoulder.Transform = Motor6Ds.LeftShoulder.Transform * (Motor6Ds.RightShoulder.Part0.CFrame:ToObjectSpace(InterpArmRoot:ToWorldSpace(RightArmDefault)))

Transform property does get overriten by your animations obviously.
You have to update it each frame.
Althrough it has to be PostSimulation afaik

I connected the function to RunService.PostSimulation instead of using RunService:BindToRenderStep. It still does nothing.

	local conn

	
	local function Update(dt:number)
		InterpCF = ShootProcedural:UpdateCFrame(TargetCF, Motor6Ds.LeftShoulder.C1, dt)

		if TarDistance > (TargetCF.Position - InterpCF.Position).Magnitude then
			TargetCF = CFrame.new()
		end

		local Speed = math.abs(TarDistance - (TargetCF.Position - InterpCF.Position).Magnitude)
		
		
		MovedArmRootCF = OffsetCFByCF(Motor6Ds.LeftShoulder.Part0.CFrame, ArmRootCF.Value)
		local InterpArmRoot = OffsetCFByCF(InterpCF, MovedArmRootCF)

		
		Motor6Ds.LeftShoulder.Transform = LeftArmDefaultTransform * (Motor6Ds.LeftShoulder.Part0.CFrame:ToObjectSpace(InterpArmRoot:ToWorldSpace(LeftArmDefault)))
		Motor6Ds.RightShoulder.Transform = RightArmDefault * (Motor6Ds.RightShoulder.Part0.CFrame:ToObjectSpace(InterpArmRoot:ToWorldSpace(RightArmDefault)))

		
		if TargetCF == CFrame.new() and Speed <= NEAR_0_NUM then		
			conn:Disconnect()
		end

		TarDistance = (TargetCF.Position - InterpCF.Position).Magnitude
	end

	conn = RunService.PostSimulation:Connect(Update)

Nvm its PreSimulation i think

1 Like

Hey thanks! That’s working!

It’s still not working quite right but because I suck at matrix transformations. But you solved my primary issue!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.