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 turn a CFrame value into a Vector 3 value?

I'm trying to make a BodyPosition value change position to be in front of the player, and above the player.. Problem is when I'm trying to get the part in front of the player, it doesn't work for some reason.. He'res the code I have:

BP.Position = player.Character.HumanoidRootPart.Position + Vector3.new(player.Character.HumanoidRootPart.CFrame.lookVector * 5) + Vector3.new(0,6,0)

What have I done wrong?

2 answers

Using plus signs in this context will simply add the Vector3 values together, in world space.

To reference a point relative to a CFrame you can do this:

CFrameHere * Vector3.new(0,3,0)

This line of code will reference a point 3 studs 'above' the CFrame.

Your code with the new implementation:

BP.Position = player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame * Vector3.new(0,6,0)

1 comment

0

That piece of code just made my character be launched in the direction he was facing. At high speeds, I just want to set the position 3 studs in front and 6 above

You can turn a CFrame value to a Vector3 value by doing this

local NewCFrame = CFrame.new(0,0,0) * CFrame.angles(0,0,0)
local NewVector3 = NewCFrame.p

CFrame.p turns a CFrame to a Vector3

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