Unbroken v0.1.32 - First Contact


Dev Diary: Update 1 (Part 2)

Previous Update | Next Update

“Good Morning, pilot!

My name is Liz Wallace, head of Science. Mankind just made first contact with the aliens and Ms. Cromwell instructed me to brief you immediately regarding the results of our sensor data analysis. Please excuse me for getting straight to the point, but considering the latest events, we must hurry.

Three alien ships have been spotted. They approach earth at constant speed. Since they have been detected by our sensors, we tried to communicate with them in all ways imaginable. As of yet, there has been no reaction whatsoever. We don’t know whether they are armed, we don’t know their goals. I’d love to get back to my team and work out a way to talk to the pilots of these ships. But the government gets increasingly tense and we have been “encouraged” to carefully prepare the interception operation and strike immediately in case any ship comes near the atmosphere of the earth. Let’s hope for the best.”

Elizabeth Wallace, Head of Science, Unbroken Organization

Release Notes

Gameplay

  • three dummy alien ships without any movement or firing behavior
  • collision detection: ships are destroyed after being hit by a single projectile
  • flight stabilization via NUMPAD0 key

Tech Talk

Ship Classes and Controllers

Soon, there will be multiple ships with different sets of data, behaviors and visuals. Since we don’t want to duplicate a lot of code whenever there are new types of ships, we will take the time to look closely into the design of ship data and behavior now.

Let’s think about what is equal for all ships. Well, each ship has an image as visual representation, a name for display, a max speed in X- and Y-direction and an acceleration in X- and Y-direction. Let’s encapsulate all of these parameters into a single ShipClass and expose them as public variables.

Ship Class Code

This allows us to view and modify the values from within the Unity inspector, and therefore create several ship classes without changing any code.

Ship Class Inspector

The ShipController (the script controlling the ship’s behavior) receives a reference to a ship class and therefore has access the contained information, so that it can still move the ship as before. Dealing with movement within the ShipController is not as straight forward as before, since the behavior of player ship and alien ships differs. We don’t want the player to be able to move the alien ships or fire their weapons via keyboard, right? What we can do is define an abstraction, that player and alien ships have in common.

ShipController

What you can see here is the Update() method of the ShipController, which gets called by Unity for each frame that it renders. Our code just checks, whether a ship may move, and if so call HandleMovement(). Similarly it checks whether a ship may fire, and if so call HandleWeapons().

Both of these methods are implemented in sub classes of ShipController, which handle the details of either the player ship or alien ships. That way, the PlayerShipController might implement movement just as we did before by listening to keyboard inputs. The AlienShipContoller does nothing but stabalize the ship at its current position. In the next iterations of the prototype, the AlienShipController will be populated with code that creates individual movement and fire behavior for alien ships.

Collision Detection

Now we want to destroy some alien ships. Therefore we need to detect, when a projectile hits a ship. “Hitting” means, the bounding geometry of the projectile and the ship touch each other. An easy solution would be to use a basic hit box (left image) for both. But that might lead to collisions being detected before the two bodies actually touch. Instead, we use a PolygonCollider (right image) to exactly trace the ships geometry.

Colliders

Now we can use the ShipController to react on other objects colliding with the ship. And if that happens, we simply destroy the game objects of the ship and the object which touches it.

To make sure, we do not get killed by our own projectiles, we forbid friendly fire. We simply check, wheter the two colliding bodies are looking at the same direction. If so, they are friendly and shall not cause a collision. Else, they are hostile and should destroy each other. For now, this just means, that they disappear from the screen. We will add explosions soon.

Collision

Flight Stabalization

In space, movement is not hindered by friction or wind resistence. Therefore our ship does not slow down its movement after an impuls of force moved it towards a certain direction. Even hitting the left arrow for a split second will have a lasting effect to the ship, moving it further and further towards the left screen edge.

In order to stop movement towards the left, another force must be applied towards the right. Since it could become tedious for the player to balance the keyboard inputs, let’s introduce the NUMPAD0 key for flight stabalization. Hitting that key will make the ship counter its current movement in X- and Y-direction until it doesn’t move at all anymore (relative to the flight speed of the camera).

Previous Update | Next Update

Get Unbroken - Mankind United

Leave a comment

Log in with itch.io to leave a comment.