Motor6D C0 & C1 Math problem

Motor6D C0 & C1 Math

Hi there, I’ve been stuck with a issue for a while. Any help would be appreciated

For the last week I’ve been having some trouble.

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

Here is a video example in @Defaultio’s game:
Link (paid access) : https://www.roblox.com/games/3540051865/test2

My current behavior looks like this:

Script source:

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)

I’ve tried using align position & align rotation.
This worked but wasn’t the best when viewed from other clients.
At that point I moved on to motor6d’s which is the way to do it with the correct math.

If you have any questions, Do ask.
Any help would be appreciated thanks!

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.