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

How would I get a magnitude between Mouse.Hit and the Player's Head?

Asked by
nanaluk01 247 Moderation Voter
6 years ago

How would I get a magnitude between Mouse.Hit and the Player's Head?

I am making a placement system where I do not want to be able to move the part inside a certain radius of the player's head.

I have currently tried doing stuff like:

if (Mouse.Hit.X - Character.Head.Position.X) and (Mouse.Hit.Y - Character.Head.Position.Y) and (Mouse.Hit.Z - Character.Head.Position.Z) >= 20 then

    --Do stuff here
end

But it does not seem to work properly, I am able to move the part to a certain extent (I can not move the part freely, it gets "locked" whenever I try moving it behind the player, but it gets locked no matter how far away I try moving it behind the player from.)

Any help is greatly appreciated!

0
I'm pretty sure there is a magnitude property of vector3's, vector2's, and maybe CFrames. hiimgoodpack 2009 — 6y
0
I think to get the magnitude, it's Mouse.Hit.p.Magnitude TheePBHST 154 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You will want to use the magnitude property of the difference of your vectors.

if (Mouse.Hit - Character.Head.Position).magnitude >= 20 then

    --Do stuff here
end
0
Error: "Magnitude is not a valid member of CFrame" nanaluk01 247 — 6y
Ad

Answer this question