Signals

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:

Example

The example below shows how to create a simple animation with a collider. When the collider is touched, the animation will start.

import { ColliderForm, EnvironmentId } from '@hiber3d/hdk-core';
import { Animation, HNode, Prefab, render } from '@hiber3d/hdk-react';
import { Collider, Ground } from '@hiber3d/hdk-react-components';
 
const World = () => (
  <HNode>
    <HNode z={5}>
      <Animation
        z={5}
        animation={{
          y: [0, 2],
          duration: 1,
          initialState: 'PAUSED',
          playOnSignal: { input: 'startAnimation', behavior: 'PLAY_UNTIL_HALF_WHEN_ON_REVERSE_WHEN_OFF' },
        }}>
        <Prefab id="cupcake_01" />
      </Animation>
 
      <Collider
        y={1}
        z={-2}
        form={ColliderForm.box}
        showMesh={true}
        sensor={{ type: 'COLLISION', output: 'startAnimation' }}
      />
    </HNode>
 
    <Ground />
  </HNode>
);
render(<World />, { environment: 'midday_01' as EnvironmentId });

Preview

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: AND-gate on a signal listener

The example below shows how to create an elevator where two buttons need to be pressed to make it move.

import { EnvironmentId } from '@hiber3d/hdk-core';
import { Animation, ButtonSensor, HNode, LogicGate, Prefab, render } from '@hiber3d/hdk-react';
import { Ground } from '@hiber3d/hdk-react-components';
 
const World = () => (
  <HNode>
    <ButtonSensor output="myButton1" z={7} x={4} />
    <ButtonSensor output="myButton2" x={2} />
 
    <LogicGate type="AND" output="myOutput" input1={'myButton1'} input2={'myButton2'} />
    <HNode z={7}>
      <Animation
        animation={{
          y: [0, 8],
          playOnSignal: {
            input: 'myOutput',
            behavior: 'PLAY_UNTIL_HALF_WHEN_ON_REVERSE_WHEN_OFF',
          },
        }}>
        <Prefab y={-8} id="en_m_primitive_soft_pillar_01" />
      </Animation>
    </HNode>
    <Ground material={'t_grass_01'} />
  </HNode>
);
render(<World />, { environment: 'midday_01' as EnvironmentId });

Preview