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
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!
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.
Other scripts that may be of interest to you are:
You can read up on how to make a custom player here.
If you want to change the default weapon a player starts with just follow these steps:
Stop the game and navigate to the section that has all of the settings
Select the “Game Controller” object and expand the “Combat - Player Equipment Manager” script
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.
The scripts that you should look at when configuring an enemy are:
Some other scripts you may find useful on enemies are:
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.
Weapon Template
Target Player Distance
Attack Distance
Allowed Distance From Spawn
Min Distance From Target
The next set of properties control how the enemy moves around the world.
Avoid Distance
Avoid Force
Avoid Duration
Max Drop Height
Unwalkable Tags
Knockback Recovery Seconds
Max Speed
Steering Strength
Gravity Acceleration
Max Vertical
Fall Max Vertical
Run Anim Gait Speed
Respawn On Fall
Kill Height
The following animation properties can only be used on NPC enemies. Voxel object enemies have separate scripts for their animations.
Idle Animation
Running animation
Falling Animation
Knockback Animation
Un Parent Time
Enemy Health
Max Hitpoints
Damage FX
Death FX
Hide Position
Respawn Delay
Respawn Ground Angle
Respawn FX
Respawn Failure Distance
Set Respawn Point On Teleport
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:
Drop Type
Collectable Drop Data Ids
Drop Position
Drop Radius
Animate Drops
Drop Fx
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.
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:
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.
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 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.
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
Attack Animation Time Scale
Attack Animation Start Time
Attack Animation End Time
Use Trigger For Attack Hitbox
Attack Range
Attack Cone Angle
Face Closest Target Within Distance
Exit Attack Animation
- Exit Attack Animation Time Scale
The playback speed of the exit attack animation.
Exit Attack Animation Start Time
Exit Attack Animation End Time
Exit Attack Animation Loop
Attack Interval
Pause Movement While Attacking
Can Damage Players
Can Damage NPCs
Can Damage Multiple Targets
Min Attack Damage
Max Attack Damage
Critical Chance
Critical Damage Multiplier
Knockback Force
Attack Fx
Parent Attack Fx
Damage Fx
Parent Damage Fx
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
Projectile Voxel Object
Aim Visual Voxel Object
Aim Visual Offset
Aim Visual Color
Aim Visual Opacity
Projectile Count
Projectile Speed
Projectile Gravity
Projectile Length
Projectile Radius
Projectile Spread
Projectile Random Spread
Projectile Spawn Offset
Projectile Angle
Projectile Scale
Projectile Lifetime
Pierce Targets
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.
I’ll cover the properties on the “Purchasable Object” script below:
Purchasable Data Id
Spawn Template On Purchase
Destroy On Purchase
Purchase Amount
Cost Label
Purchased Label
Purchase Screen Id
Purchase Fx
Purchase Sound
Cannot Purchase Sound
Interaction Arrow Offset
Interaction Arrow Voxel Object
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
Notify Camera
Teleport FX
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.
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.