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

Making a part spawn 5 studs in front of a camera?

Asked by
LuaQuest 450 Moderation Voter
9 years ago

So I'm trying to make a part spawn in the same direction a player camera is facing, but 5 studs in front of their view. So basically:

local Camera = workspace.CurrentCamera
local Part = Instance.new("Part",Camera) -- to make it local
Part.Anchored = true
Part.CFrame = Camera.CoordinateFrame

The above example would spawn a part with the exact same CFrame as the camera, including which direction it's facing. All I need is to make it keep every other CFrame position, including it's facing direction, except be 5 studs farther away from where the camera is facing. Can anyone help?

Btw, here was my attempt at doing so:

local Camera = workspace.CurrentCamera
local Part = Instance.new("Part",Camera) -- to make it local
Part.Anchored = true
Part.CFrame = Camera.CoordinateFrame * CFrame.new(Camera.CoordinateFrame.lookVector*5)

-- (I'm pretty sure it has something to do with lookVector)

Answer this question