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

Spawn part in front of player's head depending on camera's rotation?

Hopefully this should be a quick question, just need some help with CFrame math.

I want to spawn a throwable object in front of the player's head, depending on where the player's camera is looking.

Click for an Epic Paint Drawing of what I'm talking about

After Googling I've tried:

local throwOffset = CFrame.new(0,0,-5)
part.CFrame = head.CFrame * throwOffset

but obviously this only works horizontally, because the player's head isn't rotating up and down.

How do I add the player's camera's look rotation onto this?

Thank you in advance!

1 answer

Just found a solution!

local throwOffset = 5 --studs in front of head for part to spawn
local newPos = head.Position + camera.CFrame.lookVector*throwOffset
part.CFrame = CFrame.new(newPos,newPos+camera.CFrame.lookVector)

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