#How to get the closest person in a direction

3 messages · Page 1 of 1 (latest)

flint spire
#

This is an example of where you do need a For Each, or atleast some sort of loop
(You could do this without one, but it could take awhile to receive all the data back from other players)

When the loop is initiated, you need to set these variables:

  • CameraDirectionOnStart
  • PlayerPositionOnStart

You will also need these variables:

  • HighestDotValue (Float Variable)
  • HighestDotValueOwner (Player Variable)

Now, for the steps:

Step 1: Run a For Each on Get All Players
Step 2: Subtract the For Each Player player position by PlayerPositionOnStart
Step 3: Normalize the value of step 2 using Vector Normalize
Step 4: Dot the value of Step 3 by CameraDirectionOnStart
Step 5: Set HighestDotValue to Step 4 and HighestDotValueOwner to the For Each Player if the value of Step 4 is less than HighestDotValue

When the loop is over, set these variables:

  • Closest Player = HighestDotValueOwner
  • Angle = Acos(HighestDotValue)
#

Define the variables using events!

#

also check out what I added on the end