mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
fix(zones): correct contains check
This commit is contained in:
@@ -13,7 +13,7 @@ local glm = require 'glm'
|
|||||||
---@field __type 'poly' | 'sphere' | 'box'
|
---@field __type 'poly' | 'sphere' | 'box'
|
||||||
---@field remove fun(self: self)
|
---@field remove fun(self: self)
|
||||||
---@field setDebug fun(self: CZone, enable?: boolean, colour?: vector)
|
---@field setDebug fun(self: CZone, enable?: boolean, colour?: vector)
|
||||||
---@field contains fun(self: CZone, coords?: vector3): boolean
|
---@field contains fun(self: CZone, coords?: vector3, updateDistance?: boolean): boolean
|
||||||
|
|
||||||
---@type table<number, CZone>
|
---@type table<number, CZone>
|
||||||
local Zones = {}
|
local Zones = {}
|
||||||
@@ -132,7 +132,7 @@ CreateThread(function()
|
|||||||
local zone = nearbyZones[i]
|
local zone = nearbyZones[i]
|
||||||
|
|
||||||
if zone.insideZone then
|
if zone.insideZone then
|
||||||
local contains = zone.thickness and glm_polygon_contains(zone.polygon, coords, zone.thickness / 4) or #(zone.coords - coords) < zone.radius
|
local contains = zone:contains(coords, true)
|
||||||
|
|
||||||
if not contains then
|
if not contains then
|
||||||
zone.insideZone = false
|
zone.insideZone = false
|
||||||
@@ -148,14 +148,7 @@ CreateThread(function()
|
|||||||
|
|
||||||
for i = 1, #zones do
|
for i = 1, #zones do
|
||||||
local zone = zones[i]
|
local zone = zones[i]
|
||||||
local radius, contains = zone.radius, nil
|
local contains = zone:contains(coords, true)
|
||||||
zone.distance = #(zone.coords - coords)
|
|
||||||
|
|
||||||
if radius then
|
|
||||||
contains = zone.distance < radius
|
|
||||||
else
|
|
||||||
contains = glm_polygon_contains(zone.polygon, coords, zone.thickness / 4)
|
|
||||||
end
|
|
||||||
|
|
||||||
if contains then
|
if contains then
|
||||||
if not zone.insideZone then
|
if not zone.insideZone then
|
||||||
@@ -273,8 +266,12 @@ local function contains(self, coords)
|
|||||||
return glm_polygon_contains(self.polygon, coords, self.thickness / 4)
|
return glm_polygon_contains(self.polygon, coords, self.thickness / 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function insideSphere(self, coords)
|
local function insideSphere(self, coords, updateDistance)
|
||||||
return #(self.coords - coords) < self.radius
|
local distance = #(self.coords - coords) < self.radius
|
||||||
|
|
||||||
|
if updateDistance then self.distance = distance end
|
||||||
|
|
||||||
|
return distance
|
||||||
end
|
end
|
||||||
|
|
||||||
local function convertToVector(coords)
|
local function convertToVector(coords)
|
||||||
|
|||||||
Reference in New Issue
Block a user