developa Posted August 23, 2017 Share Posted August 23, 2017 Hello, what is the function of Vector3? How can this be replaced with getDistanceBetweenPoints3D on Vector3? Link to comment
Mr.Loki Posted August 23, 2017 Share Posted August 23, 2017 (edited) 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 August 23, 2017 by Mr.Loki 1 Link to comment
Mr.Loki Posted August 23, 2017 Share Posted August 23, 2017 I also forgot to mention that you can also use vectors in functions that requires position data such as setElementPosition, setElementRotation,getWorldFromScreenPosition and lots more. setElementPosition(localPlayer, middleOfMap) Link to comment
developa Posted August 23, 2017 Author Share Posted August 23, 2017 OK, thank you. And is it going to change math.random to something else? For example local rnd = random(5, 10) Or not? Link to comment
Mr.Loki Posted August 23, 2017 Share Posted August 23, 2017 It won't and it is better to localize those math functions for better performance local random = math.random local rn = random(10) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now