Signals
Signals are a way for objects in the Hiber Engine to interact with each other.
To set up a signal connection in HDK you need two things, a Sensor
and a Listener
.
Sensors
This is the object that triggers the signal. These components have an output
prop which acts as an id of the signal.
These are the available signal sensors:
Listeners
This is the object that listens for the signal and reacts to it. These components have an input
prop which takes a signal id. To connect a listener to a sensor set the input
prop to the same value as the output
prop of the sensor you want to listen to.
These are the available signal listeners:
VisibleOnSignal
InvisibleOnSignal
MaterialOnSignal
SpawnPrefabOnSignal
- Triggering animations:
playOnSignal
prop on animation components (Example: Spinning) - Playing audio:
playOnSignal
prop on audio components (Example: PointSound) - Toggling light:
lightOnSignal
prop on light components (Example: Spotlight)
Example
In the example below we add a LookAtSensor
at the same position as the sphere and a InvisibleOnSignal
around the wall. We connect the sensor and listener by setting the output
prop of the sensor and the input
prop of the listener to the same value, in this case sphereSignal
. This means that when the player looks at the sphere the wall will become visible.
import { HNode, InvisibleOnSignal, LookAtSensor, Prefab, render } from '@hiber3d/hdk-react';
import { Ground } from '@hiber3d/hdk-react-components';
const World = () => (
<HNode>
<Ground />
<Prefab id="sphere_01" y={1} />
<LookAtSensor output="sphereSignal" mesh="sphere" scale={1.1} y={2} />
<InvisibleOnSignal input="sphereSignal">
<Prefab id="en_m_log_cabin_01_wall" y={4} z={10} />
</InvisibleOnSignal>
</HNode>
);
render(<World />, { environment: 'midday_clear_01' });
Logic Gates
Logic gates are a way to combine multiple signals into one. You can use them as the target of a signal listener, or as a property of a signal source. These are the available gates:
Example: OR-gate on a signal listener
Below we modified the example above so the wall becomes invisible when the player looks at either the sphere or the cube.
import { HNode, InvisibleOnSignal, LookAtSensor, OrGate, Prefab, render } from '@hiber3d/hdk-react';
import { Ground } from '@hiber3d/hdk-react-components';
const World = () => (
<HNode>
<Ground />
<Prefab id="sphere_01" y={1} x={-3} />
<LookAtSensor output="sphereSignal" mesh="sphere" scale={1.1} y={2} x={-3} />
<Prefab id="cube_01" y={1} x={3} />
<LookAtSensor output="cubeSignal" mesh="box" scale={1.1} y={2} x={3} />
<OrGate inputs={['sphereSignal', 'cubeSignal']} output="orSignal" />
<InvisibleOnSignal input="orSignal">
<Prefab id="en_m_log_cabin_01_wall" y={4} z={10} />
</InvisibleOnSignal>
</HNode>
);
render(<World />, { environment: 'midday_clear_01' });