#Does this make sense? Because.. it *sort of* works...

1 messages · Page 1 of 1 (latest)

brazen falcon
#

local function areTheySafe(head)
local headPos = head.Position
local SafeZone = workspace.SafeZone
local safePos = SafeZone.Position
local distance = math.abs(headPos.X - safePos.X) + math.abs(headPos.Y - safePos.Y) + math.abs(headPos.Z - safePos.Z)
if distance >= SafeZone.Size.X/2 -- then the player is outside the safe zone
then return false
else return true
end
end

After much experimentation, this code is almost giving me what I desire. I have a safe zone for my character, the NPCs don't come into a small area that I have specified.
The problem is, they are encroaching - the area they don't come into is smaller than I had anticipated. I want them to stay outside of this fenced area, that is totally encompassed by my SafeZone part, and they instead, jump the fence and then stop.
But if I say
if distance >= SafeZone.Size.X/2 +10
or
if distance >= (SafeZone.Size.X/2) +10
or
if distance +10 >= SafeZone.Size.X/2
or even
local distance = math.abs(headPos.X - safePos.X) + math.abs(headPos.Y - safePos.Y) + math.abs(headPos.Z - safePos.Z)+10

there is no difference in their interpretation of the fenceline.
(Of course, I guess I could always make the part bigger, or the fenceline smaller, but that doesn't help me learn anything. 🙂 )

#

I think I need a better calculation for the part size?

brazen falcon
#

I have a vague memory of Suphi explaining something like this in a video, but I've looked through a bunch and haven't found it yet, idk which one.

noble trail
#
local function AreTheySafe(head)
  return (safeZone.Position - head.Position).Magnitude < safeZone.Size.X / 2
end