Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How to Make Your Own Combat Game in dot big bang

Combat Example

Introduction

The Combat Example is a small game with enemies spread across various islands that you can fight to collect coins, potions and weapons.

Enemies have some basic behaviors that make them chase and attack players with melee and ranged weapons. They drop loot when killed and respawn over time. An enemy can be anything from a basic voxel object to a fully animated NPC.

All aspects of the game are very customizable and it is meant to be remixed and expanded on by you!

Check it out here: https://dotbigbang.com/game/083b54d1e6a24a7ba658696aaa27ae51/basic-combat-example

How to make your own Combat Game!

The first thing you need to do is click the “Remix” button in the top left of the game. This will create a copy of the game that you own and drop you into it in edit mode.

Next stop the game and take a look at all of the elements in the world. You will see several small islands and a collection of settings and templates we’ll call the “Work Room”.

The Work Room is a hidden place where you can easily access and change all of the various settings and objects in the game. You can also add your own new elements to the game here.

The sections below will go into more detail about each aspect of the game and explain how to adjust or create your own!

Player

In this example we have set up a custom player that all players use. If you want to make your own player template you should ensure that the following scripts are on it.

  • Combat - Health
    • Allows you to configure hitpoints and respawn behavior
  • dbb_player_state
    • Saves data so players keep all of their currency and items

Other scripts that may be of interest to you are:

  • Flash When Damaged
    • Makes the player or enemy flash a color over a period of time when they take damage
  • Blob Shadow
    • Places a voxel object below the player or enemy and fades it out if they move into the air

You can read up on how to make a custom player here.

Starting Weapon

If you want to change the default weapon a player starts with just follow these steps:

  1. Stop the game and navigate to the section that has all of the settings

  2. Select the “Game Controller” object and expand the “Combat - Player Equipment Manager” script

  3. Change the “Starting Top Data Id” field to the Data Id of the desired weapon

    Note: You can find the weapon Data Ids in the “Weapon Data” scripts on the “Cosmetic and Weapon Database” object. This is also where you add your own weapons.

To create and set a new custom weapon as a starting weapon you will need to read the “Weapons” section to see how those are set up and then reference the new weapon’s Data Id.

Enemies

Enemies in this example are spread throughout the game. They will detect players moving into a radius and then chase that player until they can attack them or the player moves too far away. Most of an enemy’s behavior can be customized by adjusting properties in the scripts on them.

An enemy can be a simple voxel object or a more complex animated NPC. We have examples of both in the game. The bat on the first island is a voxel object that plays different animations depending on what it is doing, while the other enemies are NPC’s.

Scripts for Configuring an Enemy

The scripts that you should look at when configuring an enemy are:

  • Combat - Enemy Behavior
    • Allows you to configure how the enemy behaves
  • Combat - Health
    • Allows you to configure hitpoints and respawn behavior
  • Drop Collectables When Killed
    • Makes the enemy drop items when they are killed

Other Useful Scripts for Enemies

Some other scripts you may find useful on enemies are:

  • Combat - Melee Weapon
    • See the “Weapons” section to understand when you would add a weapon script directly to an enemy
  • Combat - Ranged Weapon
    • See the “Weapons” section to understand when you would add a weapon script directly to an enemy
  • Combat - Health Bar
    • Shows the player or enemy health above them
  • Flash When Damaged
    • Makes the player or enemy flash a color over a period of time when they take damage
  • Blob Shadow
    • Places a voxel object below the player or enemy and fades it out if they move into the air
  • Voxel Object Animation Controller
    • Only needed if the enemy is a voxel object and you want to play animations for attacks and movement
  • Voxel Object Animation
    • Used alongside the Voxel Object Animation Controller to define which frames go with each animation

Enemy Behavior

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. I’ll step through the options and explain what each one does.

General Enemy Properties

  • 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.p

Properties for How Enemies Move

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.

Properties for NPC Skeletal Object Enemies

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.
  • Enemy Health

    • The “Combat - Health” script contains properties that let you set up how many hit points an enemy has as well as how, or if, they respawn after dying.
  • Max Hitpoints

    • This is how many hit points the enemy will start with.
  • Damage FX

    • This template will be spawned each time the enemy takes damage. Make sure the template removes itself from the game when it is done by using a “dbb_destroy_after_delay” script.
  • Death FX

    • This template will be spawned when the enemy dies. Make sure the template removes itself from the game when it is done by using a “dbb_destroy_after_delay” script.
  • Hide Position

    • Dead enemies are moved to this position instead of being removed from the game. This is so they can manage their own respawning.
  • Respawn Delay

    • The number of seconds a dead enemy will wait before respawning.
  • Respawn Ground Angle

    • The maximum slope in degrees that the enemy can respawn on.
  • Respawn FX

    • This template will be spawned when the enemy respawns. Make sure the template removes itself from the game when it is done by using a “dbb_destroy_after_delay” script.
  • Respawn Failure Distance

    • If any players or enemies are within this distance of the respawn position when the enemy attempts to respawn it will attempt to respawn in the closest empty space above.
  • Set Respawn Point On Teleport

    • If true, the enemies respawn position will change if they are teleported to a new location.

Enemy Loot Drops

The “Drop Collectables When Killed” script lets you configure what is dropped and how far from the enemy it drops. Drops can appear for all players, just for the killer or in more advanced use cases the “owner” or player that spawned the enemy. Our example doesn’t use the “owner” type but it is there for advanced users who understand how to use something like that.

Drops can just appear on the ground within a radius of the enemy or they can animate in a curve from the enemy to their final position. Visual effects templates can also be spawned for extra polish.

I’ll explain what each property on the script does:

General Drop Properties

  • Drop Type

    • All Players - When killed the drops will appear on all players screens and each player can collect a copy of the drops. The enemy must be networked for this to work.
    • **Killer **- The drops will only appear on the killer’s screen for them to collect.
    • Owner - The drops will only appear on the screen of the player that “owns” the enemy in the networking sense. This is the case if that player spawned the enemy. This is an advanced type that should only be used by those with a good understanding of dot big bangs networking.
  • Collectable Drop Data Ids

    • A comma separated list of Ids that match entries in “Collectable Drop Data” scripts in the “Collectable Drop Database” object in the Work Room.
  • Drop Position

    • An optional offset from the enemy that the drop will spawn at.
  • Drop Radius

    • The radius out from the drop spawn position that the drop can animate to or appear at. Good for scattering multiple drops.
  • Animate Drops

    • If true, the drops will animate in an arc from the enemy to their final positions.
  • Drop Fx

    • An optional template that will spawn when the drops appear. Make sure the template removes itself from the game when it is done by using a “dbb_destroy_after_delay” script.

The comma separated list of ids lets you share drop data among enemies and can help cut down on the total data in your game, though you can also just assign a single drop to each enemy since drops themselves can contain multiple types of collectables.

To edit or add this data just select the “Collectable Drop Database” object and look at the “Collectable Drop Data” scripts on it. The ids in this data are linked to the “Collectable Database” object with “Collectable Data” scripts.

Let’s use the first Collectable Drop Data entry as an example. This entry contains the drops for the boss at the end of the level. You can see that the Data Id is “Boss Drop” and that it drops 3 Coins, 1 Potion and 1 Key.

Those Coin, Potion and Key Ids point to Collectable Data entries in the “Collectable Database”. Selecting that and inspecting the scripts will show you the data used for those. You can read up on how that data works here.

NPC and Voxel Object Enemies

There are two types of enemies supported in this game. NPC enemies are fully animated and can hold objects. Voxel Object Enemies are simpler voxel objects and require some different setup. The game contains both types so you can pretty easily create your own enemies of either type by using ours as a base.

Voxel object enemies have a couple extra optional scripts that let you control their animation since they can’t play animations like the NPC enemies.

If you select the Bat enemy on the first island you will see a “Voxel Object Animation Controller” script and several “Voxel Object Animation” scripts.

The animation controller script is listening to events from other scripts and playing the animations related to those events. You shouldn’t need to make any changes to the animation controller properties unless you are trying to make a more advanced enemy.

Each “Voxel Object Animation” script defines a specific set of frames for each animation. Looking at the top one you will see the “idle” animation loops frames 1 to 5.

The supported Animation Ids for this game are:

  • idle
  • running
  • falling
  • melee_attack
  • ranged_attack

To work with our system these ids must match exactly, but you can also add your own animation ids and use scripts to play them if you are a more experienced programmer.

When you build your enemy in the Voxel Object Editor you need to add sets of frames for each state in sequence. If you look at the bat in the Voxel Object Viewer you will see it looping through all of its frames. You can remix it to see how we’ve used the frames for the various states.

Ground Loot and Boss Chest

The bone and coin piles scattered around can be interacted with. When the player does this Collectables will appear and they can grab them. These are all “Collectable Containers” that we used in Doodle Safari and can be read about here: https://docs.dotbigbang.com/pages/examples/doodle-safari/collectable-container.html

The chest at the end is very similar except we have extended it into a “Locked Collectable Container”. This lets you remove a number of Collectables from the player when they open it, in our case a single key.

Potions

Potions are Collectables just like the Keys and Coins, but since they have an effect when used we had to make a new script for them. In the “Collectable Database” object you will see a “Healing Item Collectable Data”. This is exactly the same as a regular “Collectable Data” but has a “Heal Amount” property.

The “UI Controller” object references this data in the “Combat - Bottom Bar UI” script. This is how you use a potion when the potion button is pressed.

Weapons

This example comes with melee and ranged weapon types. These scripts can be placed on weapons that players and NPCs hold, or directly added to NPCs. They can also be stacked. For example, you could have a monster that melee attacks in a radius around it and also launches projectiles.

All of the weapons in the example can be found in the Work Room area. I recommend that you look through the properties on them to see what kind of configuration you can have. I’ll also list out the properties below. Also select the bat or the boss enemies to see weapon scripts added directly to enemies.

The melee weapon script is “Combat - Melee Weapon”. It can be set to use its own trigger volume, or a cone angle and distance around the weapon when an attack happens.

Here are the properties on that:

  • Attack Animation

    • Only used on players or NPC enemies. This animation will be played when an attack happens. If the weapon is using its own hitbox it will be activated during this animation.
  • Attack Animation Time Scale

    • The playback speed of the attack animation.
  • Attack Animation Start Time

    • This is the time in seconds that the attack animation will start at. Useful for shortening long animations.
  • Attack Animation End Time

    • This is the time in seconds that the attack animation will end at. Useful for shortening long animations.
  • Use Trigger For Attack Hitbox

    • If true, the “Attack Cone Angle” and “Attack Range” will be ignored and instead a collider on the weapon will be used while the attack is in progress.
  • Attack Range

    • If not using a trigger, the distance from the weapon that an attack can hit a target.
  • Attack Cone Angle

    • If not using a trigger, the angle of a cone, in degrees, in front of the weapon the attack can hit targets in.
  • Face Closest Target Within Distance

    • If true, will make the attacker face the nearest valid attack target within this distance. This works like an aim assist on mobile and can make attacking feel better.
  • Exit Attack Animation

    • Only used on players or NPC enemies. If set, this animation will play after an attack. Other animations like movement may override this animation.

- Exit Attack Animation Time Scale

  • The playback speed of the exit attack animation.

  • Exit Attack Animation Start Time

    • This is the time in seconds that the exit attack animation will start at. Useful for shortening long animations.
  • Exit Attack Animation End Time

    • This is the time in seconds that the exit attack animation will end at. Useful for shortening long animations.
  • Exit Attack Animation Loop

    • If true, the exit attack animation will loop.
  • Attack Interval

    • The time in seconds between attacks. Trying to attack too early will fail.
  • Pause Movement While Attacking

    • If true, the player or enemy will stop moving during the attack. This is used to make animation look better as a moving and attacking player can have sliding feet.
  • Can Damage Players

    • If true, this weapon will damage players if they are within range of an attack. You need to ensure that attackable targets are on the same collision layer as the weapon.
  • Can Damage NPCs

    • If true, this weapon will damage enemies if they are in range of an attack. You need to ensure that attackable targets are on the same collision layer as the weapon.
  • Can Damage Multiple Targets

    • If true, the weapon will damage each target it hits during an attack. Otherwise only the first target hit will be damaged.
  • Min Attack Damage

    • The smallest amount of damage a hit can cause.
  • Max Attack Damage

    • The largest amount of damage a hit can cause.
  • Critical Chance

    • The chance (0 - 1) that a hit will be a critical hit and have its damage multiplied.
  • Critical Damage Multiplier

    • The multiplier to apply to critical hit damage.
  • Knockback Force

    • The amount of force to apply to a hit target in a direction away from the weapon.
  • Attack Fx

    • The template to spawn when an attack happens.
  • Parent Attack Fx

    • If true, the “Attack Fx” template will be parented to the weapon. This can be used to make swipe effects.
  • Damage Fx

    • The template to spawn when a target is hit.
  • Parent Damage Fx

    • If true, the “Damage Fx” template will be parented to the weapon.

The ranged weapon script is “Combat - Ranged Weapon”. These weapons fire projectiles and have a variety of ways to customize how the projectiles behave. This script shares many properties with the melee weapon script so I’ll outline the differences below:

**Note:** Ranged weapons do not currently work on mobile. This will be patched when we get the ability to read more information about mobile touch positions.
  • Projectile Template

    • If set, this template will be spawned as the projectile. Otherwise the “Projectile Voxel Object” will be used. One of these must be set.
  • Projectile Voxel Object

    • If set, and a template is not set, this will be spawned as the projectile.
  • Aim Visual Voxel Object

    • This is spawned and used as the aim direction visual. This is only used by players.
  • Aim Visual Offset

    • This can be used to shift the spawn location of the aim visual object.
  • Aim Visual Color

    • The emissive color of the aim visual object is set to this color.
  • Aim Visual Opacity

    • Can be used to make the aim visual object transparent.
  • Projectile Count

    • How many projectiles should be fired per attack?
  • Projectile Speed

    • The speed of the projectiles when they are fired.
  • Projectile Gravity

    • The downward force applied to the projectile as it moves.
  • Projectile Length

    • Projectiles look for capsule overlaps to find targets as they travel. This is the length of that capsule.
  • Projectile Radius

    • The radius of the projectile capsule. Larger numbers result in wider projectiles.
  • Projectile Spread

    • The angle, in degrees, of the cone in front of the weapon that projectiles can fire in.
  • Projectile Random Spread

    • If true, projectiles will be randomly placed into the “Projectile Spread” cone. Otherwise they will be evenly spaced across it.
  • Projectile Spawn Offset

    • Can be used to adjust the spawn location of projectiles to make them appear to be coming out of the correct location.
  • Projectile Angle

    • An angle offset to apply to projectiles. This can be used to make them shoot up into the air or off to one side.
  • Projectile Scale

    • The scale applied to the projectile object.
  • Projectile Lifetime

    • The number of seconds a projectile exists in the game before being automatically removed.
  • Pierce Targets

    • The number of targets a projectile can hit and move through before being removed.

Purchases / Store

You can spend coins you have collected on weapons on one of the islands in this example. The “Purchasable Object” script manages these purchases for you by trading a Collectable for a Weapon. Since “Weapon Data” scripts in the “Cosmetic and Weapon Database” object have “Cost” and “Cost Collectable Data Id” properties they work with the purchasing system.

As long as the player has the “dbb_player_state” script any purchases will be automatically saved.

Purchasable Object Properties

I’ll cover the properties on the “Purchasable Object” script below:

  • Purchasable Data Id

    • This must match the “Data Id” on a “Weapon Data” or other compatible data script in a Database.
  • Spawn Template On Purchase

    • If set, this template will be spawned when a purchase occurs. This can be useful for things like spawning a door to a new area, or a new vehicle.
  • Destroy On Purchase

    • If set, this object will be removed from the game when purchased. Useful for allowing access to a new area.
  • Purchase Amount

    • The number of purchasables that should be given to the buyer.
  • Cost Label

    • The text to display on a Text Component on this object if it is available to purchase. Some special strings will let you display values based on the player save data and purchase data. For example: “{cost} {costDisplayName}s” will show up as “5 Coins” or something similar based on the actual data.
    • These special strings are:
      • {displayName}
      • {description}
      • {cost}
      • {maxOwnable}
      • {costDisplayName}
      • {costDescription}
  • Purchased Label

    • The text to display on a Text Component on this object if it is already purchased. The same special strings that “Cost Label” can use are valid here.
  • Purchase Screen Id

  • Purchase Fx

    • If set, this template will be spawned when a purchase happens. Make sure the template removes itself from the game when it is done by using a “dbb_destroy_after_delay” script.
  • Purchase Sound

    • If set, this sound will play when a purchase happens.
  • Cannot Purchase Sound

    • If set, this sound will play when a purchase attempt fails.
  • Interaction Arrow Offset

    • Can be used to move the location of the interaction icon.
  • Interaction Arrow Voxel Object

    • Can be used to change the interaction icon to a custom one.

Teleporters

The islands in this example are linked by bridges. In this case players don’t walk across the entire bridge, but teleport from one end to the other when they get close enough. This is handled with the “dbb_teleport_on_contact” script. Each bridge has a copy of this script on it and references an invisible target object as the spot the player will move to. This script has a few properties on it:

  • Target

    • The entity to move the player to when they teleport.
  • Notify Camera

    • If true, the camera will set its rotation based on the new rotation of the player when they teleport.
  • Teleport FX

    • If set, this template will be spawned at the new location of the player when they teleport. Make sure the template removes itself from the game when it is done by using a “dbb_destroy_after_delay” script.

UI

The UI / Hud in this example is set up in the same way Doodle Safari is set up. You can read about that on the dot big bang docs page.

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.