Get player coords with no decimals
#1
I need to compare 2 position variables, and they are always diferent because they are X.135369.. Or Z.168375
Any way to solve this?
Reply
Thanks given by:
#2
This should work:
local Pos1 = Vector3i(Player1:GetPosition())
local Pos2 = Vector3i(Player2:GetPosition())
return Pos1:Equals(Pos2)
Reply
Thanks given by: tonibm19
#3
Either that, or use Lua's built-in math.floor() or math.ceil() functions.
Reply
Thanks given by: tonibm19
#4
Do they work with Vectors?
Reply
Thanks given by:
#5
No, they only work with individual coords.
Reply
Thanks given by: NiLSPACE
#6
And anyway, what is it that you're trying to do? Wouldn't it be eaiser to check if the distance between the two positions, if it's below a threshold?
local Pos1 = Player1:GetPosition()
local Pos2 = Player2:GetPosition()
if ((Pos1 - Pos2):Length() < 1) then
  -- The positions are less than 1 block apart
end
Reply
Thanks given by:
#7
I need to compare a variable to the players position, and if its the same , teleport to another position (in a variable)
The code STR said worked fine, would your code be less performance-heavy doing it every tick as I do now?
Reply
Thanks given by:
#8
Doesn't really matter, they perform roughly the same.
Reply
Thanks given by:
#9
Oh this should also work btw:
local Pos1 = Player1:GetPosition():Floor()
local Pos2 = Player2:GetPosition():Floor()
if (Pos1 == Pos2) then
   -- Do stuff
end
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)