Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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 

1 comment

0

Not sure how you would use this but LookVector might be handy

1 answer

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 

2 comments

0

There's problem though, It won't float above the shoulder, And the offset thing you did also made it spin.

0

The code I posted is just a snippet, you have to implement it into your function.  See my edit.

This discussion is preserved as it was. New answers, comments, and votes are closed.