Get RAPTOR

Your own character

Connect your game's player, input and host to Logic and to RAPTOR's Play button.

Logic runs without code. In the editor, a scene without a camera plays with RAPTOR's built-in capsule. This page covers connecting Logic to your own character, input or host.

How Logic finds the player

When Play starts, Logic uses the first match in this order:

OrderWhat it looks forWhat Logic can do with it
1A character registered with RaptorLocalPlayers.RegisterMove, teleport, freeze and lock its input while it is dead.
2A GameObject tagged PlayerMove and teleport it through its CharacterController, Rigidbody or Transform, in that order. Cannot lock its input.
3The main cameraMove and teleport the nearest CharacterController on the camera or its parents, otherwise the camera itself. Cannot lock its input.
4NothingGraphs still run. The Console logs once that no player was found.

Built games have no RAPTOR capsule, so add your character to the scene.

Trying Logic with a tagged character

To try Logic with your character, tag it Player and make its camera a child. Implement IRaptorLocalPlayer when Logic needs to freeze the character or lock its input while it is dead.

Implement IRaptorLocalPlayer

Add IRaptorLocalPlayer to your character's controller script and register it while the character is enabled.

MemberWhat Logic uses it for
RootThe character's root, positioned at the feet.
EyeThe player's camera. Logic uses it to aim at buttons and shake the view.
InputLockedSet to true by Logic while the player is dead or frozen. Ignore move, look and jump input while it is true.
Teleport(feet, yawDegrees)Puts the feet at a point, facing a direction. 0 faces +Z, 90 faces +X.
MyPlayer.cs
using Raptor.Components;
using UnityEngine;

[RequireComponent(typeof(CharacterController))]
public class MyPlayer : MonoBehaviour, IRaptorLocalPlayer
{
    [SerializeField] Camera eye;
    CharacterController controller;

    public Transform Root => transform;
    public Camera Eye => eye;
    public bool InputLocked { get; set; }

    void Awake() => controller = GetComponent<CharacterController>();

    void OnEnable() => RaptorLocalPlayers.Register(this);
    void OnDisable() => RaptorLocalPlayers.Unregister(this);

    public void Teleport(Vector3 feet, float yawDegrees)
    {
        controller.enabled = false; // a CharacterController overrides a direct move while enabled
        transform.SetPositionAndRotation(feet, Quaternion.Euler(0f, yawDegrees, 0f));
        controller.enabled = true;
    }

    void Update()
    {
        if (InputLocked) return; // dead or frozen: skip your own move, look and jump
        // ... your movement code
    }
}

Registrations are cleared at the start of every Play session, so registering in OnEnable is enough. Without IRaptorLocalPlayer, the Freeze node logs one warning.

Your own use button

Logic's local host uses E as the use key, or the gamepad west button when the Input System package is installed. To use your own input:

Stop RAPTOR reading the key

Set RaptorLogicLocalHost.ReadsUseKey = false.

Call Press and Release from your input code

Call RaptorLogicLocalHost.Press() when your button goes down, and RaptorLogicLocalHost.Release() when it comes up. A logic button with Hold for set is used once your input has been held that long.

Draw your own prompt (optional)

While the player looks at a button, the host shows its key and Prompt near the bottom of the screen, such as E Use. To draw your own, set RaptorLogicLocalHost.ShowUsePrompt = false.

using Raptor.Logic;

void Start() => RaptorLogicLocalHost.ReadsUseKey = false;

void OnUse(bool down)
{
    if (down) RaptorLogicLocalHost.Press();
    else RaptorLogicLocalHost.Release();
}

Your own weapon

Call DamageObject to damage a logic object with Health from your weapon. The damage counts as a player hit, so Hurt by: Players allows it.

using Raptor.Logic;

void OnHit(GameObject target, float damage)
{
    RaptorLogicLocalHost.DamageObject(target, damage);
}

RaptorLogicLocalHost.ObjectDestroyed fires when a logic object with Health loses its last HP. Subscribe from OnEnable or Start to add a break effect, score or sound. Subscribers are cleared at the start of every Play session.

void OnEnable() => RaptorLogicLocalHost.ObjectDestroyed += OnBroken;
void OnDisable() => RaptorLogicLocalHost.ObjectDestroyed -= OnBroken;

void OnBroken(GameObject obj) { /* your effect */ }

Your own Logic host

RAPTOR's local host runs Logic for one player on one machine. A game that runs Logic itself, such as a networked game, claims Logic before the first scene finishes loading, and the local host does not start.

using Raptor.Logic;
using UnityEngine;

static class MyGameLogic
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    static void ClaimLogic() => RaptorLogicHosts.Claim("my game");
}
RuleDetail
A claim lasts one Play sessionClaims are cleared at the start of every session. Claim again each time, as the example does.
The first claim winsClaiming again with the same name has no effect. A different name is refused with a warning.
A late claim still worksIf the local host has already started, it stops on its next frame. A session never has two hosts.

Logic's runtime services are not supported API

A custom host drives Logic's runtime services, which are not in this reference and may change in any update.

The player RAPTOR shows in the editor

The Player Reference, placed with the Logic tool's Player mode, shows a figure of the player. By default, it uses the humanoid prefab, eye height and body radius from Edit → Project Settings → RAPTOR → Player, or a built-in mannequin.

To supply them from code, implement IRaptorPlayerProfile and register it from an [InitializeOnLoad] class with RaptorPlayerProfiles.Register(new MyProfile()).

Taking over the Play button

To start Play differently in some scenes, such as by hosting a session and spawning your player, register an IRaptorPlaytestProvider with RaptorPlaytest.Register. RAPTOR then hands Play in those scenes to your project.