Enemies¶
The Enemy component turns any object into a reactive combat NPC: it senses players (and rival factions), chases them, attacks, patrols, flees when hurt, and can be killed and respawn — with no scripting. All of its behaviour runs on the server, so a modified client can neither move it nor fake its hits; every client just sees the synced result.
Quick start
Use Social Scape ▸ SDK ▸ Create Combat Enemy to drop a ready capsule enemy into the scene, then bake a NavMesh and press Play in the Test Player. Everything below is how to tune it.
Set it up¶
- Add Enemy (
Add Component ▸ Social Scape/Enemy). It automatically adds Health (its HP + death response) and Network Transform (server-owned position sync) — you don't add those yourself. - Give it a Collider (a Capsule Collider is fine) so players and weapons can hit it.
- Bake a NavMesh for the world (
Window ▸ AI ▸ Navigation, or a NavMesh Surface). Without one the enemy is shootable but can't move — the inspector warns you if none is baked nearby.
That's the whole setup. The enemy guards its start point until a target comes into range, then chases and attacks.
Faction & targeting¶
| Field | What it does | Default |
|---|---|---|
| Team | Faction id, mirrored onto this object's Health. 0 = neutral. Enemies never attack their own non-zero team. |
0 |
| Attack Players | Whether players are valid targets. Turn off for an enemy that only fights other factions. | on |
How factions fight: an enemy targets players (if Attack Players is on) plus any enemy on a different non-zero
team. Two enemies on the same team ignore each other. Neutral (team 0) is a special case: factioned enemies never
treat a neutral enemy as a rival, but a neutral enemy will itself hunt every factioned enemy. Give your monsters
team 1, your town guards team 2, and they'll fight each other on sight.
Perception¶
| Field | What it does | Default |
|---|---|---|
| Aggro Range | Detects a target within this distance (m). | 15 |
| Lose Range | Gives up once the target is beyond this. Keep it > Aggro Range so it doesn't flicker in and out. | 22 |
| Leash Range | How far it will chase from its start before breaking off and walking home. 0 = no leash. |
30 |
| Require Line Of Sight | Must actually see the target (a raycast) to notice it. Off = senses through walls. | on |
| Line Of Sight Mask | Which layers block sight (walls / level geometry). | Default |
| Eye Height | Where the sight ray starts, above the pivot. | 1.6 |
Movement & attack¶
| Field | What it does | Default |
|---|---|---|
| Move / Chase Speed | Patrol/return speed vs. pursuit speed (m/s). | 3.5 / 5.5 |
| Turn Speed | How fast it rotates to face its target (deg/s). | 360 |
| Stop Distance | How close it gets before stopping to attack. Keep it ≤ Attack Range. | 1.8 |
| Attack Range | Reach of an attack (m). | 2.2 |
| Attack Damage | Damage per hit (applied and clamped server-side). | 10 |
| Attack Cooldown | Seconds between hits. | 1.2 |
Stop Distance must sit inside Attack Range
If Stop Distance is larger than Attack Range, the enemy halts before it's close enough and never lands a hit. The inspector flags this.
Damage is server-authoritative
Like every other source of damage, the enemy's hits are applied by the server against the target's Health (or a player). Hitting a player still respects the world's PvP rules for weapons, but an enemy's melee is part of your world's rules and always lands when in range.
Flee, patrol & death (optional)¶
- Flee Below HP % — when its health drops under this fraction it runs from its target (and returns to the fight if it
heals back up).
0= never flee, fights to the death. - Patrol Points — a list of transforms it walks in order while idle, looping back to the first. Empty = guard the start point.
- On Death —
- None — stays down where it died (its Health On Death response still runs).
- Respawn — returns to its start at full HP after Respawn Delay seconds.
- Despawn — disappears.
Respawn needs a non-destructive death
Pair Respawn with a Health On Death response that doesn't destroy the object — a Destroy action can't be undone, so a destroyed enemy can't come back. Ragdoll / hide / play-audio responses are fine.
Animation (optional)¶
Bring your own Animator + controller and name the parameters here — every client drives it from the server's motion and combat beats. Leave any name empty to skip it.
| Param | Type | Driven when | Default name |
|---|---|---|---|
| Speed | Float | Set to the enemy's current move speed each frame — blend idle / walk / run. | Speed |
| Attack Trigger | Trigger | The instant it attacks. | Attack |
| Hurt Trigger | Trigger | It takes damage but survives. | Hurt |
| Death Trigger | Trigger | It dies. | (empty) |
| Respawn Trigger | Trigger | It respawns. | (empty) |
Death & Respawn are off by default
Death Trigger and Respawn Trigger start empty so they don't double up with a Health On Death animation. Set them only if you want the Animator (rather than a Health response) to play the death/revive.
Testing¶
Add the SDK Test Player (Social Scape ▸ SDK ▸ Create Test Player) and press Play — the enemy's server AI runs in the editor, so it will chase and attack you. (In the live game the same AI runs on the game server.)
Known limits¶
- A baked NavMesh is required for movement. No NavMesh → the enemy is shootable but stationary.
- Keep enemy object names unique within a scene/parent. Two enemies with the same name under the same parent share one network identity, so damage and animations can land on the wrong one. (This applies to any Health object.)
- Enemies spawned at runtime by a script (rather than placed in the world) may not animate until the platform learns their identity; enemies you place in the world always do.
Beyond the component¶
Enemy covers the common cases with no scripting. For behaviour it doesn't — a custom state machine, a scripted boss
phase, your own targeting rules — run a NexusScript on the server with a Server Script
so your logic is authoritative and can call Combat.* / Health.*.
Related¶
- Health & combat — the HP / death model the enemy uses, and the PvP switch.
- Weapons — what players shoot enemies with.
- World objects — placing and testing objects.
- Server scripts — the scripted, custom-AI counterpart to this component.
- Combat scripting — dealing damage and reading health from a script.
Component class names (for scripts and search): SSEnemy.