Skip to content

Targetable

Making game objects targetable using the Combat module’s Targetable component is trivial for Game Creator Characters and other game objects.

Basic Setup#

Characters#

To make a character targetable, simply add the Targetable component to it.

Targetable Character

Non-Character Game Objects#

Any game object can be targetable if it has the Targetable, Rigidbody, and Collider components.

Targetable Non-character

Making a Target Untargetable#

The Targetable component contains a boolean Game Creator Variable property, called Can Be Targeted, that can make the target untargetable.

For example, once the target has been defeated, it is likely desirable for the player to automatically stop targeting it and not be able to target it again.

This is accomplished by:

  1. Adding a boolean Local Variable to a character (e.g. "IsAlive").
  2. Assigning the boolean variable to the Can Be Targeted property.
  3. In the character’s On Receive Shot Actions, set the boolean value to false - this will deselect the target and make it no longer targetable.

The Combat Examples module’s Example4-KillableCharacters demo scene contains a pre-configured KillableCharacter prefab. It demonstrates how to make a character killable/untargetable using the method described above.

Visibility Detection Renderer

This property is used to determine if a Targetable's mesh is visible to a Targeter component. It does not normally need to be manually set (if not set, the component uses the first renderer found in the object's hierarchy). This property only needs to be manually set if the Targetable component's parent object does not have a mesh renderer in its hierarchy, or a mesh renderer other than the first one the GetComponentInChildren<Renderer>() returns by default is required.

If visibility features are not used, this property can be ignored completely.

"On Target Become Untargetable" Trigger#

New in 0.4.0

There is also a trigger called "On Target Become Untargetable" that allows for actions to be executed when the target becomes untargetable. The Combat Examples module’s Example7-DestructibleTargets demo scene contains a pre-configured DestructibleTarget prefab. It showcases how to use this trigger to implement destructible targets.

Advanced Options#

Active Target Indicator#

The Targetable component provides an "indicator" feature that highlights the currently targeted game object. The content and appearance of the indicator is configurable.

Active Target Indicator

Text#

An indicator can have custom text, defined via a Game Creator Global/Local Variable. Practically speaking, it almost always makes sense to use a Local Variable packaged in the same prefab object that contains the Targetable component. The value of the Local Variable would then be configured on the instance of the prefab when used in a scene.

Active Target Indicator Text

Prefab#

If not set, the Game Creator Floating Message prefab is automatically set as the target indicator prefab at runtime. The Combat Examples module includes an example of a custom indicator. The example indicator has text above a downward pointing arrow.

Active Target Indicator Prefab

Positioning#

The target indicator is positioned relative to the parent game object. By default, the Indicator Offset vector will position the indicator above the Game Creator example character, but may need to be adjusted for other characters and objects of with heights.

Active Target Indicator Offset

Targeting Actions#

A Targetable game object can optionally execute actions when it becomes the active target, and another set of actions when some other object becomes the active target (or targeting is toggled off altogether).

Targeting Actions

"On Become Active Target"#

When the target becomes the active target, these actions can (for example) make the target crouch. A more practical example might be adding an outline around the target or perhaps set a variable that triggers some behavior (e.g. make the target hostile or flee).

On Become Active Target

"On Not Active Target"#

Related to the previous section, when the target is changed or targeting is disabled, this action will reset the target character’s gesture state.

On Not Active Target

"On Continuing To Be Targeted"#

Actions that are periodically executed while the target continues to be targeted. This is useful, for example, for repeating an attack on an enemy with a cooldown or otherwise having the target behave in some specific way.