Monday, May 2, 2022
HomeWebsite DesignAdd Extra Enjoyable to a Recreation: Extending "The Aviator"

Add Extra Enjoyable to a Recreation: Extending “The Aviator”

From our sponsor: Strive Mailchimp immediately.

Should you like cute little video games you’ll love Karim Maaloul’s “The Aviator” — as a pilot you steer your plane throughout a spherical little ocean world, evading purple “enemies” and gathering blue vitality tokens to keep away from crashing into the water. It runs solely within the browser so ensure that to shortly play a spherical to raised perceive what we’re about to do on this tutorial.

By the best way, Karim co-founded the Belgian inventive company Epic. His type is exclusive in its adorableness and his animation craftmanship is astonishing as you can too see in his sequence of WebGL experiments.

Karim fortunately wrote concerning the making of and open sourced the code and whereas it’s a enjoyable little sport there’s nonetheless a number of potential to get much more out of it. On this article we are going to discover some hands-on modifications on tips on how to deliver probably the most enjoyable based mostly on the muse we’ve right here, a small browser sport utilizing Three.js.

This tutorial requires some information of JavaScript and Three.js.

What makes a sport enjoyable?

Whereas there clearly is not any definitive recipe there are just a few key mechanics that can maximize your possibilities of producing enjoyable. There’s a nice compilation on, so let’s see which gadgets apply already:

Nice controls
An fascinating theme and visible type
🚫 Wonderful sound and music
🚫 Fascinating worlds
🤔 Enjoyable gameplay
🚫 Stable degree design
🚫 An entertaining story & memorable characters
🤔 Good stability of problem and reward
One thing completely different

We are able to see there’s heaps to do, an excessive amount of for a single article after all, so we are going to get to the final sport format, story, characters and stability later. Now we are going to enhance the gameplay and add sounds — let’s go!

Including weapons

Weapons are all the time enjoyable! Some video games like Area Invaders consist solely of taking pictures and it’s a nice mechanic so as to add visible pleasure, cool sound results and an additional dimension to the ability requirement so we not solely have the up and down motion of the plane.

Let’s attempt some easy gun designs:

The “Easy gun” (prime) and the “Higher gun” (backside).

These 3D fashions encompass solely 2–3 cylinders of shiny metallic materials:

const metalMaterial = new THREE.MeshStandardMaterial({
    shade: 0x222222,
    flatShading: true,
    roughness: 0.5,
    metalness: 1.0

class SimpleGun {
    static createMesh() {
        const BODY_RADIUS = 3
        const BODY_LENGTH = 20

        const full = new THREE.Group()
        const physique = new THREE.Mesh(
            new THREE.CylinderGeometry(BODY_RADIUS, BODY_RADIUS, BODY_LENGTH),
        physique.rotation.z = Math.PI/2

        const barrel = new THREE.Mesh(
            new THREE.CylinderGeometry(BODY_RADIUS/2, BODY_RADIUS/2, BODY_LENGTH),
        barrel.rotation.z = Math.PI/2 = BODY_LENGTH

        return full

We may have 3 weapons: A SimpleGun, then the DoubleGun as simply two of these after which the BetterGun which has only a bit completely different proportions and one other cylinder on the tip.

Weapons mounted to the airplane

Positioning the weapons on the airplane was executed by merely experimenting with the positional x/y/z values.

The taking pictures mechanic itself is straight ahead:

class SimpleGun {
  downtime() {
    return 0.1

  harm() {
    return 1

  shoot(course) {
    const BULLET_SPEED = 0.5
    const RECOIL_DISTANCE = 4
    const RECOIL_DURATION = this.downtime() / 1.5

    const place = new THREE.Vector3()
    place.add(new THREE.Vector3(5, 0, 0))
    spawnProjectile(this.harm(), place, course, BULLET_SPEED, 0.3, 3)

    // Little explosion at exhaust
    spawnParticles(place.clone().add(new THREE.Vector3(2,0,0)), 1,, 0.2)

    // Recoil of gun
    const initialX =, {
      period: RECOIL_DURATION,
      x: initialX - RECOIL_DISTANCE,
      onComplete: () => {, {
          period: RECOIL_DURATION,
          x: initialX,

class Airplane {
  shoot() {
    if (!this.weapon) {

    // rate-limit taking pictures
    const nowTime = new Date().getTime() / 1000
    if (nowTime-this.lastShot < this.weapon.downtime()) {
    this.lastShot = nowTime

    // hearth the shot
    let course = new THREE.Vector3(10, 0, 0)

    // recoil airplane
    const recoilForce = this.weapon.harm(), {
      period: 0.05,
      x: - recoilForce,

// in the primary loop
if (mouseDown[0] || keysDown['Space']) {

Now the collision detection with the enemies, we simply verify whether or not the enemy’s bounding field intersects with the bullet’s field:

class Enemy {
	tick(deltaTime) {
		const thisAabb = new THREE.Box3().setFromObject(this.mesh)
		for (const projectile of allProjectiles) {
			const projectileAabb = new THREE.Box3().setFromObject(projectile.mesh)
			if (thisAabb.intersectsBox(projectileAabb)) {
				spawnParticles(, 5, Colours.brownDark, 1)
				projectile.take away()
				this.hitpoints -= projectile.harm
		if (this.hitpoints <= 0) {

	explode() {
		spawnParticles(, 15, Colours.purple, 3)
		sceneManager.take away(this)

Et voilá, we are able to shoot with completely different weapons and it’s tremendous enjoyable!

Altering the vitality system to lives and cash

At present the sport options an vitality/gasoline bar that slowly drains over time and fills up when gathering the blue capsules. I really feel like this is smart however a extra typical system of getting lives as well being, symbolized by hearts, and cash as goodies is clearer to gamers and can permit for extra flexibility within the gameplay.

Within the code the change from blue capsules to golden cash is straightforward: We modified the colour after which the geometry from THREE.TetrahedronGeometry(5,0) to THREE.CylinderGeometry(4, 4, 1, 10).

The brand new logic now could be: We begin out with three lives and at any time when our airplane crashes into an enemy we lose one. The quantity of collected cash present within the interface. The cash don’t but have actual affect on the gameplay however they’re nice for the rating board and we are able to simply add some mechanics later: For instance that the participant should purchase accessoires for the airplane with their cash, having a lifetime coin counter or we may design a sport mode the place the duty is to not miss a single coin on the map.

Including sounds

That is an apparent enchancment and conceptually easy — we simply want to seek out becoming, free sound bites and combine them.

Fortunately on and we are able to seek for sound results and use them freely, simply ensure that to attribute the place required.

Instance of a gun shot sound:

We load all 24 sound recordsdata at first of the sport after which to play a sound we code a easy‘shot-soft’). Repetitively taking part in the identical sound can get boring for the ears when taking pictures for just a few seconds or when gathering just a few cash in a row, so we ensure that to have a number of completely different sounds for these and simply choose randomly which one to play.

Bear in mind although that browsers require a web page interplay, so principally a mouse click on, earlier than they permit a web site to play sound. That is to stop web sites from annoyingly auto-playing sounds instantly after loading. We are able to merely require a click on on a “Begin” button after web page load to work round this.

Including collectibles

How will we get the weapons or new lives to the participant? We are going to spawn “collectibles” for that, which is the merchandise (a coronary heart or gun) floating in a bubble that the participant can catch.

We have already got the spawning logic within the sport, for cash and enemies, so we are able to undertake that simply.

class Collectible {
	constructor(mesh, onApply) {
		this.mesh = new THREE.Object3D()
		const bubble = new THREE.Mesh(
			new THREE.SphereGeometry(10, 100, 100),
			new THREE.MeshPhongMaterial({
				clear: true,
				opacity: .4,
				flatShading: true,

	tick(deltaTime) {
		rotateAroundSea(this, deltaTime, world.collectiblesSpeed)

		// rotate collectible for visible impact
		this.mesh.rotation.y += deltaTime * 0.002 * Math.random()
		this.mesh.rotation.z += deltaTime * 0.002 * Math.random()

		// collision?
		if (utils.collide(airplane.mesh, this.mesh, world.collectibleDistanceTolerance)) {
		// passed-by?
		else if (this.angle > Math.PI) {
			sceneManager.take away(this)

	explode() {
		spawnParticles(, 15, COLOR_COLLECTIBLE_BUBBLE, 3)
		sceneManager.take away(this)'bubble')

		// animation to make it very apparent that we collected this merchandise

perform spawnSimpleGunCollectible() {
	const gun = SimpleGun.createMesh()
	gun.scale.set(0.25, 0.25, 0.25) = -2

	new Collectible(gun, () => {
		airplane.equipWeapon(new SimpleGun())

And that’s it, we’ve our collectibles:

The one drawback is that I couldn’t for the lifetime of me create a coronary heart mannequin from the three.js primitives so I resorted to a free, low-poly 3D mannequin from the platform cgtrader.

Defining the spawn-logic on the map in a strategy to have a superb stability of problem and reward requires wise refining so after some experimenting this felt good: Spawn the three weapons after a distance of 550, 1150 and 1750 respectively and spawn a life a short time after dropping one.

Some extra polish

  • The ocean’s shade will get darker as we progress by the degrees
  • Present extra prominently once we enter a brand new degree
  • Present an finish sport display after 5 ranges
  • Adjusted the code for a more recent model of the Three.js library
  • Tweaked the colour theme

Extra, extra, extra enjoyable!

We went from a easy fly-up-and-down gameplay to with the ability to acquire weapons and shoot the enemies. The sounds add to the environment and the cash mechanics units us up for brand new options in a while.

Ensure that to play our consequence right here! Acquire the weapons, have enjoyable with the weapons and attempt to survive till the tip of degree 5.

If you’re within the supply code, you discover it right here on GitHub.

proceed from right here? We improved on some key mechanics and have a correct foundation however this isn’t fairly a finalized, polished sport but.

As a subsequent step we plan to dive extra into sport design concept. We are going to have a look at a number of of the preferred video games of the limitless runner style to get insights into their construction and mechanics and the way they preserve their gamers engaged. The goal could be to be taught extra concerning the superior ideas and construct them into The Aviator.

Subway Surfer, probably the most profitable “limitless runner” sport.

Keep tuned, so lengthy!

Superior Demos Roundup #20
UI Interactions & Animations Roundup #23



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments