wiki.sine.space | sinespace

Enemy NPCs and NPC spawners

From wiki.sine.space
Revision as of 05:33, 2 March 2019 by HannahT25 (Talk | contribs) (NPC spawner)

Jump to: navigation, search

The NPC Spawners spawn NPCs that will then attack players. Standard NPCs currently attack with melee actions. (Ranged NPCs are in development.)

Enemy NPCs have configurable settings for range, attack rate and damage, and for damage, attack, death and victory events.

NPC Spawners are placeable inventory items that players can deploy in their maps and which will spawn NPCs according to their settings. Individual NPC spawners can spawn multiple NPC types.

Public variables on the NPC spawner allow players to customise settings including spawn rate and lifetime of NPCs.

This video tutorial shows how to configure and publish your own Enemy NPCs and NPC Spawners as inventory items that players can in place in their multi-player maps in Sinespace;


PENDING


NPCS

Public Variables

There are 15 public variables on the NPC.


attackModes

This number should parallel the number set up in the NPC’s Animation Controller.

In the default Animation Controller there are four unique attack moves, two damage moves, one kill celebration and one death move.

You can alter these but remember to define that in the parameters here. Animations are selected randomly.


attackRange

Attack range is the distance from the player at which the NPC will begin it’s attack animation.

To get a good experience you want to align three different distances; the attackRange, the meleeRange (below) and the radius of the collider on the NPC.

The collider hitting the player is the actual damage event.

The meleeRange, also a public variable on the NPC script, defines the closest the NPC will get to the player; if it gets too close then the player’s gun will stick out behind the NPC and the player will not be able to shoot the NPC. The NPC may be partially off camera and it’s attack animations will probably look wrong.

For a regular biped you might set attackRange to 2 meters, set the radius of the collider to 1.5 and set the meleeRange to 1 meter.


deathModes

deathModes, like the attackModes, defines the number of death sequences the NPC will randomly select from. Double click on the dying node in the first layer of the Animation Controller and you can see the four options the default art pack offers.


damageModes

damageModes are also randomly selected, as animations playing when the NPC takes damage.


meleeRange

meleeRange is the closest the NPC will get to the player before stopping moving toward the player.


intervalNoTarget

intervalNoTarget defines how often the NPC will scan the scene looking for players during it’s idle cycles. It defaults to 5 seconds which to be honest makes for some pretty sleepy NPCs. You might set yours to 1 second. Much lower than that could impact performance in a scene full of NPCs.


intervalTarget

intervalTarget defines how often the NPC scans for players when it is actively hunting and attacking a player; the default is .25 seconds which should be sufficient for any NPC.


viewDistance

viewDistance defines how far the NPC can see. The NPC cannot see behind itself. It will attack if a player shoots it but does not (yet!) attack if it sees a bullet go by.


viewHeight

viewHeight is the height the NPC scans for players at. If you are working with our standard character player avatar system or any regular biped costume avatars you shouldn’t need to adjust this.


attackSpeed

attackSpeed defines how fast the NPC moves when hunting and attacking the player.


wanderSpeed

wanderSpeed defines the NPC’s idle movement speed.


collisionDamageValue

collisionDamageValue defines how much damage the NPC does each time it strikes.


collisionInterval

collisionInterval defines how often the NPC inflicts damage when the player is within the NPC’s collider.


repeatDamage

repeatDamage is a toggle, 0 or 1. Leave it on 1 for any regular attacking NPC. If you are creating some kind of bomb or other single attack event set repeatDamage to 0 to go off only once when triggered.


startHealth

startHealth defines the amount of health the NPC has when it spawns.


Events

There are 9 available events on the NPC.

  • Spawn
  • Hide
  • Die

The Spawn, Hide and Die events are configured with specific triggers that the game depends on. Please don’t change these settings.

  • Discover
  • Attack
  • Attackend
  • Losttarget
  • Damage
  • Kill

The other six are available for triggering various events at your discretion.


Object references

There are three object references;

HealthValue and HealthWrapper reference the world space canvas on the NPC that is hovering over its head. You can change the font and size of these if you want to bring them in line with the rest of your game UI. The animator references the AO for the NPC. The Trigger activator triggers damage from the capsule collider. Again note it needs to be set to owner only. The navmesh agent and character controller are both standard Unity components. Both are required for the NPC to function. The default settings should be fine for a regular biped.

Please note the navmesh agent should be left disabled in your project.

NPC spawner

The NPC Spawner is a spawnable furniture item that players can place in their maps to spawn enemt NPCs that will attack players.


Public variables

There are seven public variables.


npcTypes

npcTypes defines the number of different NPCs that the spawner will emit.

Each NPC type needs to be referenced in the Resources below. If you upload a spawner that spawns 3 enemy types and you let the player change the number, going over 3 wont’ do anything. Coming down to 2 or 1 will cut back on a numbered basis; e.g. if the player sets this to 1 inworld then only the npc1 in the Resources will spawn.


npcPoolSize

npcPoolSize defines the number of NPCs that will be created and set inactive, per type, per spawner in the scene. Running a pool of NPCs improves performance compared to destroying and creating NPCs individually.

To calculate the appropriate pool size you need to consider three factors;

  • Lifetime of NPC
  • Spawn rate
  • Types

For example, if the lifetime of an NPC is 60 seconds and the spawn rate is three seconds you can only ever have two in the scene at once from that spawn point. So the pool required is 2 max.

If you have multiple different types the pool actually comes down because it will pool for every type and it will cycle through types in order not randomly.

To cross check your pool size use this calculation;

Lifetime / spawn interval / type, then round up.


npcSpawnMinRange and npcSpawnMaxRange define the radius from the Spawner where the NPCs will appear. You might want them to spawn from one single spawner across the whole map randomly or you might want to lock it down so they visually appear in the middle of a visible portal.

npcLifetime defines the lifetime of individual NPCs, which will die on their own when their lifetime expires. You might want to set this to be higher than the default 60 seconds. If you set it too high you will risk exceeding your pool and further NPCs may not spawn until the available ones are killed. If you dramatically increase both the pool and the npcLifetime you might hit some performance issues.

If you are developing a map or a game that is more like a coop campaign than an arena then you might set your npcLifetime very high and the spawn rate (the delay between spawing) very high too, or put a trigger on the spawner itself that switches it off completely once the first generation of NPCs are spawned.

npcSpawnHeight lifts the biped above the ground when it spawns to ensure it does not spawn fractionally below the terrain.


Resources

Add all your NPC types to the resources slots available. The name of the prefab doesn’t matter but the naming convention on the resources does and it should be npc1 npc2 etc. all lower case.


Events

There is one event available which is the spawn event. You can add a particle effect or anything else you want to coincide with the enemy being spawned.