guides:proximity-trigger
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
guides:proximity-trigger [2021/02/23 11:47] – fix minotorious | guides:proximity-trigger [2021/02/23 12:05] (current) – initial article minotorious | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Custom Component: Proximity Trigger ====== | ====== Custom Component: Proximity Trigger ====== | ||
+ | |||
+ | <code lua> | ||
+ | local COMP_PROXIMITY_TRIGGER = { | ||
+ | TypeName = " | ||
+ | ParentType = " | ||
+ | Properties = {} | ||
+ | } | ||
+ | |||
+ | function COMP_PROXIMITY_TRIGGER: | ||
+ | -- Position of the Prefab the component is assigned to | ||
+ | local pos1 = self: | ||
+ | | ||
+ | -- Using COMP_AGENT to include non-villagers too like the Envoy | ||
+ | self: | ||
+ | function(comp) | ||
+ | -- Position of the Agent | ||
+ | local pos2 = comp: | ||
+ | | ||
+ | -- Computing distance between Agent and Prefab | ||
+ | local distance = math.sqrt( (pos1.x - pos2.x)^2 + (pos1.y - pos2.y)^2 + (pos1.z - pos2.z)^2 ) | ||
+ | | ||
+ | if distance < 4 then -- you can set this distance as close to the object as you need | ||
+ | -- Do fancy stuff | ||
+ | end | ||
+ | end | ||
+ | ) | ||
+ | end | ||
+ | </ |
guides/proximity-trigger.txt · Last modified: 2021/02/23 12:05 by minotorious