I am trying to spawn a part 6 studs in front of the character, no matter how it’s rotated.
Here is my current code:
local Model = workspace.Rig
local Part = Instance.new("Part")
Part.Size = Vector3.new(0,0,0)
Part.Parent = workspace
Part.Position = Model.HumanoidRootPart.Position + Vector3.new(0,0,-6)
At the moment the part isn’t always spawning in front of the player. I’m not that experienced with vector and cframe. but does anyone have a fix for this?
All contributions appreciated! Thanks!
You can use
CFrame.LookVector and do some vector calculations to get The position 6 studs in front.
CFrame.LookVector will return a Vector value means no rotation.
maybe use the CFrame instead of Position?
local function FindPosition(RootPart, OffsetStuds)
-- Add the multiplied direction to the current position
return RootPart.Position + RootPart.CFrame.LookVector * OffsetStuds
I would do it like this:
local p = Instance.new("Part",workspace)
p.Position = (game.Players[SomePlayer].Character.HumanoidRootPart*CFrame.new(0,0,-6)).p
-- p.CFrame= game.Players[SomePlayer].Character.HumanoidRootPart*CFrame.new(0,0,-6)
Forgot for a hot minute that Instance has 2 arguments.