dot big bang

Developer API
Menu
All
  • Public
  • Public/Protected
  • All

Enemy behavior in this example is pretty basic, but still flexible enough to make some fun gameplay.

Enemies will stay where they started until they notice a player. Once they see a player they will chase them and try to attack them until the enemy dies, the player is dead, or has run out of range. Then the enemy will return to the starting point and wait to see a player again or respawn later if possible.

The Combat - Enemy Behavior script has a lot of options to let you fine tune how an enemy reacts to players. Let's step through the options and see what each one does.

  • Weapon Template

    • This only works on NPC enemies that can have objects attached to them. This lets you set a weapon for the enemy to use. The weapon needs to be set up properly so see the Weapons section to learn about that. This can be left blank if you want to add weapon scripts directly to the enemy, or if the enemy is a voxel object.
  • Target Player Distance

    • If a player gets within this distance of the enemy and the enemy is not currently targeting another player, the enemy will target the player and start moving toward them to attack.
  • Attack Distance

    • If the enemy is within this distance to their target they will begin attempting to attack them. Depending on the configuration of the weapon scripts, on the enemy or held weapon, attacks may or may not happen.
  • Allowed Distance From Spawn

    • The enemy will chase a target up to this distance and then stop targeting them and begin moving back to where they started.
  • Min Distance From Target

    • The enemy will try to stay at least this distance away from the target. This is useful for enemies using ranged weapons as it will make them stay back and fire at the player.

The next set of properties control how the enemy moves around the world.

  • Avoid Distance

    • If the enemy detects an obstacle within this distance it will begin trying to move around it.
  • Avoid Force

    • This is the force applied in the direction the enemy goes when avoiding obstacles. Larger numbers result in faster movements.
  • Avoid Duration

    • This is the duration each "Avoid Force" is applied for. This can be tweaked to get smoother avoidance.
  • Max Drop Height

    • If the enemy is at a drop it will move over it if the ground below the drop is within this distance.
  • Unwalkable Tags

    • Any ground objects that have these tags on them will be avoided by the enemy.
  • Knockback Recovery Seconds

    • The amount of time an enemy takes to start moving again after being knocked back by a player weapon.
  • Max Speed

    • The fastest an enemy can move when following a player or moving back to their starting point.
  • Steering Strength

    • This controls how fast the enemy turns as it faces its target.
  • Gravity Acceleration

    • The acceleration applied when the enemy is not on the ground.
  • Max Vertical

    • The maximum vertical speed an enemy can move at. This can be used to reduce enemy knockback if they get sent into the air.
  • Fall Max Vertical

    • The maximum speed the enemy can fall at.
  • Run Anim Gait Speed

    • This is used to tweak the running animation based on the enemy’s speed. If you change the animation you may need to adjust this so the feet are not sliding on the ground as the enemy moves.
  • Respawn On Fall

    • If true, the enemy will respawn if they hit the "Kill Height".
  • Kill Height

    • The y value at which an enemy will be killed. If they manage to fall off a platform this can be used to get them to respawn back where they started.

The following animation properties can only be used on NPC enemies. Voxel object enemies have separate scripts for their animations.

  • Idle Animation

    • This animation will play while the enemy has no target.
  • Running animation

    • This animation will play while the enemy is moving.
  • Falling Animation

    • This animation will play while the enemy is falling.
  • Knockback Animation

    • This animation will play when the enemy is knocked back.
  • Un Parent Time

    • Used to smooth out collisions while walking off objects.