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

How do I get a Vector3 from a CoordinateFrame (CFrame)?

Asked by
Discern 1007 Moderation Voter
9 years ago

I have a Part with a BodyPosition inside. I want the BodyPosition's position property (Which is Vector3) to be where my mouse is pointing (mouse.Hit, Which is CFrame).

This is what I have right now:

local mouse = game.Players.LocalPlayer:GetMouse()

wait(10)

game.Workspace.Part.BodyPosition.position = Vector3.new(mouse.Hit)

Every time though after 10 seconds of randomly moving my mouse, the position property still reads 0,0,0 every time (Meaning it has not changed).

There is no output.

How can I make it so the position property is where my mouse is?

NOTE: This is inside a LocalScript and FilteringEnabled is NOT on.

0
Or I think if you want you can just write game.Workspace.Part.BodyPosition.position = mouse.Hit XToonLinkX123 580 — 9y
0
Tried that, I get an error in Output "Vector 3 expected, got userdata". Discern 1007 — 9y
0
Discern, long time no see! I got more reputation, more than last time at least! (By a hundred). EzraNehemiah_TF2 3552 — 9y
0
@Lord I kinda took a break from scripting/developing and focused on war clans for a while for the fun of it... Lol. Hopefully I'm back to developing and right now I'm making a new game! Discern 1007 — 9y

2 answers

Log in to vote
2
Answered by 9 years ago

There is a simple way, there is sometimes a .p property of CFrame values. For example:

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Hit.p -- <-- That is now a Vector3
game.Workspace.Part.CFrame.p -- <-- also now a Vector3

Hope it helped

0
Wow! Thanks mate! Who knew two letters could fix all my problems? :D I never knew about that .p property. Discern 1007 — 9y
Ad
Log in to vote
-3
Answered by 9 years ago

Simply wrap it up with a nice Vector3.new()

Vector3.new(CFrame.new(5,1,5))

0
That's exactly what I did, mate. mouse.Hit is a CFrame value. Discern 1007 — 9y

Answer this question