Skip to content

Samples designed as exercises to be ported from Unity GameObjects/MonoBehaviours to Unity DOTS.

License

Notifications You must be signed in to change notification settings

ParsGameLab/DOTS-training-samples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Under the 'Originals' directory, you'll find small simulations/games implemented in classic (non-DOTS) Unity. Your task is to implement one of these samples in DOTS.

  1. Clone this repository.
  2. Make a new branch for your sample port.
  3. Create a new Unity Project and place it under the 'Ported' directory, e.g /Ported/AutoFarmers/
  4. Configure the project for DOTS.

Feel free to copy assets and code snippets from the originals into your ports. The focus of this exercise is to familiarize yourself with the DOTS API and to practice Data-oriented Design principles!

Sample Gallery

Expand the arrows for more details about each sample.

Ant Pheromones: Ants look for food and spread pheromones to influence the pathing of other ants.
Click here for details
  • Ants bring food from the source (green spot) to the destination (red spot).
  • Each ant spawns at the center point with a random heading.
  • Ants bounce off of walls at the inverse angle.
  • Ants will steer towards the food source (green dot) if they have line of sight.
  • Ants leave pheromone in the spots they walk over.
  • Ant steering is biased towards the nearest adjacent spot of pheromone.
  • Pheromone at a spot decays over time.
  • Ant steering is also slightly randomized, so ants don’t walk in straight lines.
  • The gaps in the ring walls randomly vary in size and placement.
  • Keyboard controls allow the user to slow down, speed up, and reset the simulation.

Ant Pheromones


Auto Farmers: Farmers gather and sell resources to expand their farm.
Click here for details
  • On start, a single farmer (the green cylinders) spawns.
  • Farmers walk around to destroy rocks (the grey cylinders) to make way for tilling the soil (creating brown-striped crop cells).
  • A plant grows in each crop cell. (The color and mesh of plant randomly varies.)
  • When fully grown, a plant is ready for harvest by a farmer. Farmers deposit plants in the nearest silo (grey-blue cylinder).
  • When enough resources have been collected into a silo, a new farmer spawns from the silo.
  • Farmers look for their next task in a limited radius. If no task is found, they look in an increasingly larger radius until a task is found.
  • For every fifth farmer spawned, a drone is spawned instead.
  • Drones fly and harvest plants. They do not destroy rocks or plant crops.
  • After depositing, drones hover over the silo until they locate a plant to harvest.
  • Keyboard controls allow the user to reset the simulation.

Auto Farmers


Bucket Brigade: Firefighters pass buckets along a chain to extinguish a fire.
Click here for details
  • Each cell of the grid has a temperature from 0.0 to 1.0. Cells above 0.2 are on fire and transmit heat to their neighbors. The color and height of a fire cell reflects its temperature. (For visual effect, a fire cell's height randomly oscilates a small amount, but this does not reflect its actual temperature.)
  • On start, a few random cells are on fire. Buckets are randomly placed around the field.
  • Workers are grouped into teams. Each team picks the closest cell on fire and forms two lines from the fire to the nearest water (blue cells outside the field). One line passes full buckets; the other passes empty buckets.
  • Each team has a bucket fetcher, who retrieves the nearest bucket, walks it to the water at the end of the line, fills the bucket, and then drops it.
  • Workers in the 'pass full' line look for full buckets on the ground within a small radius. When found, they walk over, pick up the bucket, carry it to the next worker up the line, and drop it. The last worker in the 'pass full' line empties the bucket on the fire (lowering the temperature of that cell and its eight surrounding cells to zero). Workers move slower while carrying a full bucket.
  • Workers in the 'pass empty' line behave the same but only carry empty buckets. The last worker in the 'pass empty' line will fill the bucket in the nearest water.
  • Every frame, a team will reposition its line to the fire cell closest to its current water source.
  • When a team's water source is exhausted, it repositions the line to the next closest water.
  • When repositioning, a worker will not resume its normal behavior until it has reached its new position.
  • In the moment between a worker placing a bucket on the ground and the next picking it up, the line might reposition, in which case the bucket will be left on the ground.
  • OPTIONAL: A small configured number of 'omniworkers' (black) are not part of any team. An omniworker picks up the nearest bucket, fills it at the nearest water source, and dumps it on the nearest fire.
  • Keyboard controls allow the user to reset the simulation.

Bucket Brigade


Combat Bees: Two bee hives battle for resources and survival.
Click here for details
  • Resources (green discs) spawn in the middle. Yellow bees spawn in the yellow base. Blue bees spawn in the blue base.
  • Resources spawned at the same location will stack on top of each other.
  • Bees pick up resources and drop them in their base.
  • When a resource hits the ground of a base, it explodes, spawning several bees of that base's color.
  • Bees not carrying resources may attack and destroy enemy bees.
  • A destroyed bee emits bee fragments and blood splatters, and the resource eventually carried falls to the ground.
  • Blood splatters on surfaces shrink to nothing over time.
  • Each bee's displayed scale oscillates along all three axes, but this is just a visual effect. Collisions are not affected.
  • Keyboard controls allow the user to reset the simulation.
  • Left mouse clicks spawn additional resources at the point clicked (determined by casting a ray from the cursor).
  • The camera can be controlled with the mouse (hold down right button to rotate, use mouse wheel to zoom).

Combat Bees


Factory: Robots transport resources along lanes to crafters.
Click here for details
  • Users can click to add a cluster of several additional bots. Users can also click on tiles of the grid to clear them or to add walls (grey tile), add a resource (purple tile), add a crafter (green tile), add green lines, or add purple lines.
  • Bots are purple when carrying a resource and green when not.
  • Bots pick up resources at the purple tiles and deliver them to the green tiles (crafters).
  • Bots will not collide with other bots. When bots are spawned, other bots gets pushed out of the way.
  • Bots will path around walls. If you place a wall on top of bots, they will remain stuck until you erase the tile.
  • Keyboard controls allow the user to reset the simulation.

Factory


Highway Racers: Simulate traffic on a 4-lane highway.
Click here for details
  • Each car has a random cruising speed, a random overtake speed, a random overtake distance, and a random overtake time (each within a fixed min/max range).
  • When traveling at its cruising speed, a car is grey. When going below its cruising speed, it turns red. While going above its cruising speed, it turns green.
  • Cars have three main states: cruising, looking to change lane, and overtaking.
  • While cruising, a car accelerates/brakes to its cruising speed; if it comes up behind a slower car within its overtake distance, it enters the 'looking to change lane' state.
  • A looking-to-change car will look for sufficient open space to its left or right to change lanes. While blocked from changing lanes, the car will tail the car ahead of it. When it is clear to change lane, it will enter the overtake state.
  • In the overtake state, a car first moves into another lane, then accelerates to its overtake speed. Once the car's overtake time elapses, it looks to move back into the lane it came from. If blocked from moving back, the car gives up and goes back to the cruising state. If at any time the car is impeded by a slower moving car within its overtake distance, it goes back to the cruising state.
  • Keyboard controls allow the user to reset the simulation.

Highway Racers


Jump The Gun: A ball jumps through a blocky landscape and avoids cannonballs.
Click here for details
  • The ball bounces from column to adjacent column towards the mouse cursor. (This requires computing the appropriate trajectory for each bounce.) The movement is clamped to the edges of the playing field.
  • On init, the cannons spawn on random columns. The cannons always turn to face the player's ball.
  • Periodically, each cannon fires a cannon ball along a trajectory that will intersect the player's ball (at its current position) but not hit any columns in between.
  • When a cannon ball hits the top of a column, the impact pushes the column down (but not below the minimum height).
  • The game is over when a cannon ball hits the player's ball.
  • Keyboard controls allow the user to reset the simulation.

Jump The Gun


LabRat: Place arrows on the board to route the most rats into your home base.
Click here for details
  • Mice spawn at frequent, randomized intervals in the top and bottom corners. The top mice head down. The bottom mice head up.
  • At start of play, walls are randomly placed between grid cells.
  • Cats and mice travel on the grid, changing direction when they hit a wall or travel over an arrow.
  • Cats spawn in random squares. When a cat and mouse intersect, the mouse is eaten.
  • When a mouse hits a player's 'home base' (one of the four dots placed near the center of the grid), the mouse disappears, and the player is awarded a point.
  • Players can place arrows in cells of the board. The green player places green arrows, the red player places red arrows, etc. A player cannot place their arrows in a cell occupied by an arrow of another player.
  • Once a player has three arrows on the board, their next placed arrow removes their oldest arrow on the board.
  • Only one player is human. The AI players just place their arrows randomly at random intervals.
  • At the end of 30 seconds, the player with the most points wins.
  • Keyboard controls allow the user to reset the simulation.

Lab Rat


Magnetic Roads: Cars drive along 3D generated splines in all orientations.
Click here for details
  • Cars drive in two lanes on both sides of the road. Cars always drive in the right lane.
  • The cars all drive at the same speed. Cars will brake before hitting the car in front of them.
  • Intersections join two or three road segments, but never four. Some intersecionts are dead ends: they connect to only one road segment.
  • At three-way intersections, each car randomly chooses whether to go left, right, or straight.
  • Cars wait to enter an intersection if their path through the intersection crosses the path of another car in the intersection.
  • Keyboard controls allow the user to reset the simulation.
  • Walls can be added at runtime by left clicking while holding the shift key down.

Magnetic Roads


Metro: Metro train transport commuters from station to station.
Click here for details
  • The trains move on a fixed schedule. Passengers should not enter or exit the train if they do not have time to get in position before the train moves.
  • Disembarking passengers randomly pick another train to board.
  • The scene contains a set of authored control points that defines splines for the tracks. Some of these control points also define the placement of stations.
  • Keyboard controls allow the user to reset the simulation.

Metro


Stack Interchange: Cars drive through a stack interchange.
Click here for details
  • At random intervals, cars spawn at the edge of the straight roads. Cars despawn when they run off the edge of the straight roads.
  • Cars merging onto a new road should yield for cars on the road.
  • Each road has two lanes. Cars in both lanes of a road travel in the same direction.
  • Cars stay in their lanes through their whole trip, e.g. a car in the left lane will travel in the left lane on all roads.
  • Each car has a color matching one of the roadways. A car's path through the interchange must include the roadway maching its color.
  • Some roadways arch upwards to pass over other roads.
  • The simulation has multiple interchanges, but each is unconnected and independent from the others. Cars of one interchange do not travel to the other interchanges.
  • Keyboard controls allow the user to reset the simulation.

Stack Interchange


Thrower Arms: Mechanical arms throw rocks at tin cans.
Click here for details
  • The arms and hands are animated by inverse kinematics.
  • The cans scroll in from the sides and wrap around.
  • Rocks scroll in from the side and get destroyed once they reach the end. Additional rocks spawn along the path to ensure all arms have sufficient rocks.
  • Two arms should never reach for the same ball.
  • An arm does not collide with rocks or with other arms. The fingers wrap around a rock but do not actually grip the rock. The rock is temporarily attached to the hand.
  • Once an arm has picked up a rock, it targets a can and calculates the required throwing trajectory). (No two arms should ever attempt to pick up the same rock or target the same can.)
  • When struck, a can is affected by gravity and the force of the hit. A single rock can hit multiple cans. Rocks are impacted by their collisions with the cans. Cans do not collide with other cans.
  • Falling rocks and cans despawn when they fall below a certain altitude.
  • Keyboard controls allow the user to reset the simulation.

Thrower Arms


Tornado: A tornado devastates a construction site.
Click here for details
  • A tornado travels along the ground in a figure 8 pattern.
  • A fixed set of cubes swirl around in the tornado.
  • The force of the tornado breaks apart the joints of the randomly spawned towers.
  • The cubes and beams are affected by the force of the tornado, but they collide only with the ground, not with each other.
  • Keyboard controls allow the user to reset the simulation.

Tornado


Zombie Maze: A circle picks up capsules in a maze infested with zombies.
Click here for details
  • A player (yellow cube) and zombies (green cubes) move along the grid of the board.
  • The interior maze walls are randomly generated at init time.
  • The magenta walls move back and forth at a regular interval.
  • The player wins by picking up all of the capsules.
  • Most zombies path towards a randoly chosen pill. When a zombie reaches its destination pill, it selects another pill target.
  • A fixed number of zombies path towards the player.
  • Keyboard controls allow the user to reset the simulation.

Zombie Maze


Deprecated samples

About

Samples designed as exercises to be ported from Unity GameObjects/MonoBehaviours to Unity DOTS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 96.7%
  • ShaderLab 3.3%