Motor6D C0 & C1 Math problem

Motor6D C0 & C1 Math

Once a player triggers a proximity prompt,
I want the model to tween towards my right hand.

local tweenservice = game:GetService("TweenService")

function Can_Collide(Parent, Bool)
    if Parent:IsA("Model") or Parent:IsA("Folder") then
        for _, Basepart in pairs(Parent:GetDescendants()) do
            if Basepart:IsA("BasePart") then
                Basepart.CanCollide = Bool
            end
        end
    end
end

function Create_Animation(Character, AnimationId)
    local Humanoid = Character:FindFirstChildWhichIsA("Humanoid", true)
    local Animation = Instance.new("Animation")
    Animation.AnimationId = tostring(AnimationId)

    local AnimationTrack = Humanoid:LoadAnimation(Animation)
    AnimationTrack:Play()
end

local function TweenC0(Motor, EndC0)
    local prop = {C0 = EndC0}
    local info = TweenInfo.new(5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
    return tweenservice:Create(Motor, info, prop):Play()
end

script.Parent.Triggered:Connect(function(player)
    local Character = player.Character
    local Test_Axe = script.Parent.Parent.Parent.Parent

    Can_Collide(Test_Axe, false)
    Create_Animation(player.Character, ("rbxassetid://7619346751"))
    
    local Motor6D = Instance.new("Motor6D")
    Motor6D.Part0 = player.Character:FindFirstChild("RightHand")
    Motor6D.Part1 = Test_Axe.PrimaryPart
    
    print(Motor6D.C0)
    
    Motor6D.C0 = Motor6D.Part0.CFrame:inverse() * Motor6D.Part1.CFrame
    Motor6D.Parent = Test_Axe.PrimaryPart
    Test_Axe.Parent = player.Character

    delay(1, function()
        TweenC0(Motor6D, CFrame.new(0, 0, 0))
        warn(Motor6D.C0)
    end)
end)
3 Likes

You didn’t really go into detail about what issues you were facing with your current approach. I assume looking at the video you want the axe to remain at its starting position and to then tween to the hand, which it’s currently not doing.

The axe is moving up because it is positioned relative to the hand. In the video you can see the hand going up, changing where the axe would be in world space. I would suggest an alternative of updating the position of the axe in a procedurally in heartbeat or something so that it smoothly moves to the hand in world space. Also, make sure you are handling this kind of animation on the client.

This old post has since been addressed and resolved.