Author Topic: Detect whether someone is in a room?  (Read 1059 times)

Is there any way to determine whether or not a person is inside or outside a room (it has to have walls/roof/floor)?

You could make a brick the size of the room that is a zone

Code: [Select]
datablock fxDTSBrickData(RoomBrickData : brick64xCubeData)
{
category = "Special";
subCategory = "Rooms";

uiName = "Room1 Brick";

        alwaysShowWireFrame = false;
isWaterBrick = true;
};

datablock TriggerData(RoomTrigger)
{
   tickPeriodMS = 100;
};

function fxDtsBrick::createRoomTrigger(%this,%data)
{

%t = new Trigger()
{
datablock = %data;
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1"; //this determines the shape of the trigger
};
missionCleanup.add(%t);

%boxMax = getWords(%this.getWorldBox(), 3, 5);
%boxMin = getWords(%this.getWorldBox(), 0, 2);
%boxDiff = vectorSub(%boxMax,%boxMin);
%boxDiff = vectorAdd(%boxDiff,"0 0 0.2");
%t.setScale(%boxDiff);
%posA = %this.getWorldBoxCenter();
%posB = %t.getWorldBoxCenter();
%posDiff = vectorSub(%posA, %posB);
%posDiff = vectorAdd(%posDiff, "0 0 0.1");
%t.setTransform(%posDiff);

%this.trigger = %t;
%t.brick = %this;

return %t;
}

package Room
{

function RoomBrickData::onAdd(%this,%brick)
{
     %brick.scheduleNoQuota(0,"createRoomTrigger","Room");
Parent::onAdd(%this,%brick);
}

function RoomBrickData::onRemove(%this,%brick)
{
     if(isObject(%brick.trigger))
          %brick.trigger.delete();
Parent::onRemove(%this,%brick);
}

function Room::onEnterTrigger(%this,%trigger,%obj)
{
messageClient(%obj.client,'',"Entered the room");
%obj.client.isInRoom = 1;
}

function Room::onLeaveTrigger(%this,%trigger,%obj)
{
messageClient(%obj.client,'',"ExetedRoom");
%obj.client.isInRoom = 0;
}

};
activatePackage(ShopTrigger);

You could make a brick the size of the room that is a zone

Code: [Select]
-snip-
it has to be dynamic because it is going to be in player built rooms and i can't rely on them building all walls and a roof and not just making a roof.

Just shoot a raycast straight up and if it doesn't hit anything, they're outside.

Just shoot a raycast straight up and if it doesn't hit anything, they're outside.
this wouldn't solve the issue of just being under a roof or something being directly under you instead of being in a proper room

possibly you could adapt a kind of 'flood fill' algorithm to detect a closed space and after x amount of ticks assume they're not in one. it may be difficult to think of an efficient way to do this in TS, and i have no idea what to google to research this
« Last Edit: January 20, 2014, 05:45:07 PM by otto-san »

this wouldn't solve the issue of just being under a roof or something being directly under you instead of being in a proper room

possibly you could adapt a kind of 'flood fill' algorithm to detect a closed space and after x amount of ticks assume they're not in one. it may be difficult to think of an efficient way to do this in TS, and i have no idea what to google to research this
yes and I also will be doing this roughly every 100ms so it needs to be efficent.

yes and I also will be doing this roughly every 100ms so it needs to be efficent.
uh wow

it'll probably be hard to get something fast, accurate, and efficient

If you're doing it ten times a second per client your best bet is to go with a single raycast upwards. In my opinion, it's not a room if there's no roof, and it's not outdoors if it has a roof. Sure, you might get gazebos or something similar that have roofs but aren't rooms, but I'd just say forget it, it's a room.

If you're doing it ten times a second per client your best bet is to go with a single raycast upwards. In my opinion, it's not a room if there's no roof, and it's not outdoors if it has a roof. Sure, you might get gazebos or something similar that have roofs but aren't rooms, but I'd just say forget it, it's a room.
oh alright :c