Jump to content

Vector


developa

Recommended Posts

A vector3 holds 3 values and can be declared by using:

v = Vector3()

It's great for storing positions. (Which I use a lot)

Using the above example would create an empty Vector returning (0,0,0)

to access the values in the vector we use variables x,y,z:
 

x = v.x
y = v.y
z = v.z
-- x = 0
-- y = 0
-- z = 0

You can even set the values of the vector

middleOfMap = Vector3(0,0,-3)

 

To replace "getDistanceBetweenPoints3D" using this method you'd need to minus 1 vector from another and use the ".length" variable:

distance = (v-middleOfMap).length

The value returned is always absolute so it never goes below 0, meaning it does not matter the order in which you subtract them.

which is the same as:

direction = (v-middleOfMap)
distance = abs(sqrt(direction.x*direction.x+direction.y*direction.y+direction.z*direction.z))

This example gets the distance between 2 players

local pos1 = getRandomPlayer(  ).position
local pos2 = getRandomPlayer(  ).position
local distance = (pos1-pos2).length
print(distance)

Also you should check out OOP

Edited by Mr.Loki
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...