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

How can I turn a CFrame value into a Vector 3 value?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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)
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 wilsonsilva007 373 — 4y
Ad
Log in to vote
0
Answered by
ew_001 58
4 years ago

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

Answer this question