Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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!

2 comments

0

I'm pretty sure there is a magnitude property of vector3's, vector2's, and maybe CFrames.

0

I think to get the magnitude, it's Mouse.Hit.p.Magnitude

1 answer

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

1 comment

0

Error: "Magnitude is not a valid member of CFrame"

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