Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Transforming Motor6Ds according to mouse location on the screen?

Asked by
Rheines 661 Moderation Voter
5 years ago
Edited 5 years ago

What I want to do is to force my character model to always view towards the mouse on the screen (not the location of the mouse in 3D space, using Mouse.Hit.p).

I've got the location of the mouse by using the origin point of Camera:ScreenPointToRay() but now I do not know how to transform the R15's Waist Motor6D to look itself towards the mouse. The character is guaranteed to force the player's screen. It is also a standard rig.

This is my current failed implementation.

function menu:LatchTorsoToMouse()
    local Camera  = workspace.CurrentCamera
    local Mouse   = Player:GetMouse()
    local Stepped = RN.Stepped:Connect(function()
        print('Stepped began.')
        if Model.Parent == nil then return end

        local ScreenPoint = Camera:ScreenPointToRay(Mouse.X, Mouse.Y, 1)
        local OriginPoint = ScreenPoint.Origin
        local Waist       = Model.UpperTorso.Waist

        Waist.Transform   = CFrame.new(Waist.Transform.p, OriginPoint) 
    end)

    return Stepped
end

It might be because of object space vs. world space or whatnot but I am also not too sure. How do I go about fixing this?

0
how does this have upvotes it's not even that good a question lo User#24403 69 — 5y
1
Yeah it's actually a simple question  :/ Rheines 661 — 5y

Answer this question