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

How can I make a floating object face the direction the player's facing?

Asked by 8 years ago

I'm making a floating doll that floats above your shoulder, But I don't know how to make it face the direction the player's facing. Could someone help me out?

Here's the script that I made to make the doll stay above the player's shoulder:

local player = game.Players.LocalPlayer

while wait(0.1) do
    local character = player.Character
    if character ~= nil then
        script.Parent.Doll.Body.BodyPosition.Position = character:FindFirstChild("Right Arm").Position + Vector3.new(0,3,0)
    end
end 
0
Not sure how you would use this but LookVector might be handy bubbaman73 143 — 8y

1 answer

Log in to vote
2
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

The easiest way to do this is to copy the rotation matrix of the character's torso's CFrame into the doll:

local cframe = character.Torso.CFrame - character.Torso.CFrame.p
local doll = script.Parent.Doll.Body
doll.CFrame = CFrame.new(doll.CFrame.p)*cframe

Now say it doesn't look quite right and you want to offset the CFrame. You can do this quite easily by multiplying the CFrame by the desired angles.

Example:

doll.CFrame = doll.CFrame*CFrame.Angles(math.rad(90), math.rad(-15), 0)

Edit:

local player = game.Players.LocalPlayer

while wait(0.1) do
    local character = player.Character
    if character then

        local cframe = character.Torso.CFrame - character.Torso.CFrame.p
        local doll = script.Parent.Doll.Body
        doll.CFrame = CFrame.new(doll.CFrame.p)*cframe
        doll.CFrame = doll.CFrame*CFrame.Angles(math.rad(90), math.rad(-15), 0)
        -- The line above is optional, depending if you want rotation

        doll.BodyPosition.Position = character["Right Arm"].Position + Vector3.new(0, 3, 0)
    end
end 

0
There's problem though, It won't float above the shoulder, And the offset thing you did also made it spin. theamazemanII 32 — 8y
0
The code I posted is just a snippet, you have to implement it into your function.  See my edit. BlackJPI 2658 — 8y
Ad

Answer this question