Ad
Log in to vote
0

How would I make the hand motor 6d face the mouse?

Asked by
A_Mp5 146
3 days ago

I have a flashlight tool, and I want to make it so the shoulder, elbow, and wrist joints will make the flashlight point at your mou8se location. I already have a script for the torso and head, but I need to replicate this onto the elbow, shoulder, and wrist joints. (r15)

local RunService = game:GetService("RunService")

local Player = game.Players.LocalPlayer
local PlayerMouse = Player:GetMouse()

local Camera = workspace.CurrentCamera

local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Neck = Head:WaitForChild("Neck")

local Torso = Character:WaitForChild("UpperTorso")
local Waist = Torso:WaitForChild("Waist")

local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local NeckOriginC0 = Neck.C0
local WaistOriginC0 = Waist.C0

Neck.MaxVelocity = 1/3

RunService.RenderStepped:Connect(function() 
    local CameraCFrame = Camera.CoordinateFrame

    if Character:FindFirstChild("UpperTorso") and Character:FindFirstChild("Head") then
        local TorsoLookVector = Torso.CFrame.lookVector
        local HeadPosition = Head.CFrame.p

        if Neck and Waist then

                local Point = PlayerMouse.Hit.p

                local Distance = (Head.CFrame.p - Point).magnitude
                local Difference = Head.CFrame.Y - Point.Y

                Neck.C0 = Neck.C0:lerp(NeckOriginC0 * CFrame.Angles(-(math.atan(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 1, 0), 0.5 / 2)
                Waist.C0 = Waist.C0:lerp(WaistOriginC0 * CFrame.Angles(-(math.atan(Difference / Distance) * 0.5), (((HeadPosition - Point).Unit):Cross(TorsoLookVector)).Y * 0.5, 0), 0.5 / 2)

        end
    end 
end)

Answer this question