Log in to vote

0
I am trying to make a certain lock on script, where if a humanoid root part is located within a certain distance of the player, on key press, you lock on to his torso, root, etc. I dont understand how this would be accomplished, if you would help, it would be much appreciated!

Log in to vote

0
https://developer.roblox.com/en-us/articles/Magnitude

when key pressed, take the position of the part you want and players humanoidrootpart. then use magnitude to find the distance between the two.

-- example with 2 players local distance = (humanoidrootpart - humanoidrootpart2).Magnitude print(distance)

0

I am trying to achieve a script like this, except it doesnt determine whether the magnitude is in range with a specific part, but with any root part in a radius ssgmalachi 52 — 9d

Log in to vote

0
If you're talking radius, then height is not a contributing factor. I wrote this function so you could compare two points to get a distance, it includes a third argument that when set to true; will ignore the height difference between the two points while calculating distance.

local function GetDistanceBetween(Point0, Point1, IgnoreHeight) local Distance = (Point0 - Point1) return (Distance * (IgnoreHeight == true and Vector3.new(1, 0, 1) or Vector3.new(1, 1, 1))).Magnitude end -- Below example. local Distance = GetDistanceBetween(Vector3.new(0, 0, 0), Vector3.new(100, 35, 100), true) print(Distance)

In the example below the function; ignoring height gives the radius (141.42135620117). If we don't ignore height, then the result would be a bit larger due to the curve caused by the height (145.68801879883).