- Oct 25, 2007
- 115
- 26
Here's a prefab showing how to create a door that is only opened when someone carrying the flag approaches it. I suggest playing around with the tutorial to get a good idea of how it works but I'll give a short explanation as well.
An example of how it works:
I've created a point_proximity_sensor (RedFlagProxSensor) parented to the item_teamflag (RedFlag). As the flag is carried around the RedFlagProxSensor will move along with it. The point_proximity_sensor is a way to determine distance from another entity. In this case the flagOnlyDoorMarker an info_target entity setup in the center of the door. When the flag is picked up the RedFlagProxSensor is set to enabled, otherwise (when dropped, captured or at the start of the map) it is disabled to save on the cost of the entity. When enabled this proxsensor, through the use of the 'Distance' output will Set the value on a logic_compare (FlagOnlyDoorDistance). Logic_compares are used to compare two values. Using the SetValue input sets one of these values (the initial value). The other value for this logic compare is already set to 192. This value represents the distance the flag has to be from the door for it to open. The Logic_Compare is given an output of LessThan which means that when this entity is told to compare its values if the InitialValue is less than the Compare Value the output will fire (and the door will open).
The Logic_Compare entity will not automatically open the door on its own though. So what we have to do is setup a trigger_multiple around the door much like you already (or should be) doing with your doors. This trigger_multiple will do two things. First it will close the door with an output on OnEndAllTouch. The second thing it does though is through the Output of OnStartTouchAll it tells the FlagOnlyDoorDistance to compare its values.
What this means is that whenever anyone gets close to the door the logic compare will compare to see how far away the flag is from the info_target entity we setup. If the flag is close enough (and being carried) the door will open. Otherwise it will remain shut. This effectively gives you a door that can only be opened by the flag carrier.
Except not quite! There's a few fringe situations we need to take care of. First what happens if the flag is dropped or captured near the door then someone approaches the door without picking up the flag? Under our current setup the door would open for them! That's not what we want. To fix this we add two outputs to our flag, one for OnDrop and on for OnCapture. Both outputs have the target of out logic_compare (FlagOnlyDoorDistance) and set the value to 9000. This means that while the flag is not being carried it's the same as if the flag was very far away from the door. Note that we have a small delay on these outputs so that the only activate AFTER the Proximity Sensor is disabled.
The second situation we need to handle is what if the flag, after being dropped near the door, is picked up. Under our current setup the door would remain shut unless the flag carrier moved away from the door then back towards it (activating the OnStartTouch of the trigger_multiple again). So 1 more output is added to the flag on OnPickup, FlagOnlyDoorDistance, Compare. This causes the Logic_Compare to check to see if it should open the door when the flag is picked up.
I know this all is kind of jumbled and hard to read but check out the map and hopefully it'll start to make sense.
If anyone has any questions about scaling this up (multiple doors, working with both flags, etc.) Let me know and I can help you out.
An example of how it works:
I've created a point_proximity_sensor (RedFlagProxSensor) parented to the item_teamflag (RedFlag). As the flag is carried around the RedFlagProxSensor will move along with it. The point_proximity_sensor is a way to determine distance from another entity. In this case the flagOnlyDoorMarker an info_target entity setup in the center of the door. When the flag is picked up the RedFlagProxSensor is set to enabled, otherwise (when dropped, captured or at the start of the map) it is disabled to save on the cost of the entity. When enabled this proxsensor, through the use of the 'Distance' output will Set the value on a logic_compare (FlagOnlyDoorDistance). Logic_compares are used to compare two values. Using the SetValue input sets one of these values (the initial value). The other value for this logic compare is already set to 192. This value represents the distance the flag has to be from the door for it to open. The Logic_Compare is given an output of LessThan which means that when this entity is told to compare its values if the InitialValue is less than the Compare Value the output will fire (and the door will open).
The Logic_Compare entity will not automatically open the door on its own though. So what we have to do is setup a trigger_multiple around the door much like you already (or should be) doing with your doors. This trigger_multiple will do two things. First it will close the door with an output on OnEndAllTouch. The second thing it does though is through the Output of OnStartTouchAll it tells the FlagOnlyDoorDistance to compare its values.
What this means is that whenever anyone gets close to the door the logic compare will compare to see how far away the flag is from the info_target entity we setup. If the flag is close enough (and being carried) the door will open. Otherwise it will remain shut. This effectively gives you a door that can only be opened by the flag carrier.
Except not quite! There's a few fringe situations we need to take care of. First what happens if the flag is dropped or captured near the door then someone approaches the door without picking up the flag? Under our current setup the door would open for them! That's not what we want. To fix this we add two outputs to our flag, one for OnDrop and on for OnCapture. Both outputs have the target of out logic_compare (FlagOnlyDoorDistance) and set the value to 9000. This means that while the flag is not being carried it's the same as if the flag was very far away from the door. Note that we have a small delay on these outputs so that the only activate AFTER the Proximity Sensor is disabled.
The second situation we need to handle is what if the flag, after being dropped near the door, is picked up. Under our current setup the door would remain shut unless the flag carrier moved away from the door then back towards it (activating the OnStartTouch of the trigger_multiple again). So 1 more output is added to the flag on OnPickup, FlagOnlyDoorDistance, Compare. This causes the Logic_Compare to check to see if it should open the door when the flag is picked up.
I know this all is kind of jumbled and hard to read but check out the map and hopefully it'll start to make sense.
If anyone has any questions about scaling this up (multiple doors, working with both flags, etc.) Let me know and I can help you out.
Last edited: