Unbroken v0.1.16 - Endless Space
Dev Diary: Update 1 (Part 1)
“Greetings, Pilot!
Just about two weeks have passed, since we all listened to the news in disbelief, when the potential threat of an alien invasion was announced for the first time. And now here we are, at the brand-new, multi-million dollar head quarters of Unbroken, a global defence organization erected within days and already buzzing with the world’s leading experts in science, engineering, space travel and military strategy. Oh, and pilots of course. I’m sure you guys will come in handy as well.
Sorry, where are my manners. I’m Chris from the Engineering department. Please, let me introduce you to your new ship. Hopefully, you two are going to have a long-lasting and trusty relationship. Get into the pilot seat for a first test flight and enjoy the endless space! This might be the calm before the storm. The aliens seem to be nowhere near, but we nevertheless installed a cannon on your ship. Just in case …”
Christopher Redborough, Head of Engineering, Unbroken Organization
Release Notes
Gameplay
- spaceship travels along infinite space
- ship movement via ARROW keys
- weapon fire via SPACE bar
- player ship cannot leave screen bounds
Tech Talk
Unity & C#
This game is created with Unity and the C# programming language. Unity provides basic features for game development, like a 3D scene to place and manipulate game objects, a game loop which allows for updating game state every frame and the possibility to attach C# scripts to ANY game object, in order to code any kind of behavior imaginable for that game object.
Infinite Space
In order to create the illusion of infinite space, we need a background image of deep space and a camera that runs upwards at a constant speed, guiding the player through the mission. That’s easy enough, but the camera reaches the end of the background image pretty quickly and exposes the level background. Pretty lame, right?
In order to fix this, we need to clone our background image and attach a duplicate right where the current image ends, whenever the camera would expose the level background. Now we DO have endless space, but shouldn’t there be an ugly border exactly where the images touch each other? This is not the case, since I am using a seamless texture (see: Dynamic Space Background Lite). Seamless textures can be repeated infinitely without any breaks or seams because each edge matches perfectly with its opposite edge.
Right now, we create a new duplicate of the background image whenever our camera reaches the top edge of the current clone. Over time, this will create countless copies of the image in memory. This is unnecessary, since we will never return, once we travelled through an area. To keep the memory footprint as small as possible, we create a total of just 2 instances of the background image and simply move the lower one on top of the upper one whenever needed.
Ship movement
The player should be able to control the ship via arrow keys. While holding the UP arrow, the ship should accelerate forwards up to a defined maximum speed. While holding the DOWN arrow, it should decelerate or even start moving backwards. The same can be applied to movement along the X-axis, respectively. While there is no keyboard input, the ship should keep its current speed towards all directions.
For now, our ship is defined by an image (see: 2D Spaceships Free Trial), its position, a maximum speed and an acceleration in X- and Y-direction respectively. In order to make it move, we need to update its position, whenever a new frame is rendered. But where to move the ship? Well, physics tells us, that the distance travelled (s) equals the velocity (v) times the time delta (t). The Unity engine provides the time delta since the last frame was rendered. And the velocity (v) equals the acceleration (a) times delta time (t).
First we calculate the delta speed since the last frame and the new total speed.
Using the new speed, we can calculate the distance travelled and thus the new ship coordinates.
Finally we can simply move the ship to its new coordinates.
Weapon Fire
The player should be able to fire the cannon via space bar. When the weapon is off cooldown, this should spawn a new projectile at the bow of the ship and move it straight forward at a constant speed in flight direction. Each projectile is defined by an image (see: 2D Space Game Pack), the projectile speed and its maximum range.
For the cooldown feature, we keep the timestamp of the last fired shot in memory. When the player hits the space bar, we add the cooldown interval to the saved timestamp. Only if the sum of both exceeds the current timestamp, the weapon is off cooldown and a projectile is fired. Else, nothing happens.
For determinining the spawn position of the projectile, we take the current ship position as a basis and then shift the y-coordinate forwards by half the ship’s image height. That way, it spawns centered right at the top edge of the ship.
After spawning, we move the projectile forwards each frame according to its projectile speed, similar to the ship movement. As soon as it has travelled its maximum range, the projectile’s game object is destroyed without any effect.
Enforcing Screen Bounds
While future enemies may move through space however they please, the player ship shall always remain within camera vision. Therefore, movement must be limited, when reaching the edges of the screen.
Luckily, the left and right edges are always at the same X-coordinate. The Y-coordinates of the top and bottom edges however need to be updated over time as the camera moves forwards. For that purpose, each frame, we add the current Y-coordinate of the camera to the initial y-coordinate of the top or bottom screen edges respectively.
Remember, how we calculated the new ship coordinates each frame? Now we add another step, which makes sure, that the ship cannot maneuver beyond the screen edges.
Get Unbroken - Mankind United
Unbroken - Mankind United
Defend Humanity against the Alien Invasion
Status | In development |
Author | Tobias Mielke |
Genre | Action |
Tags | 2D, Singleplayer, Space, Unity |
Languages | English |
More posts
- Unbroken v0.7.264 - Modular Ship BuildingSep 06, 2022
- Unbroken v0.6.187 - Boss FightAug 14, 2022
- Unbroken v0.5.162 - Ship ModulesAug 06, 2022
- Unbroken v0.4.136 - Sounds GoodAug 05, 2022
- Unbroken v0.3.106 - Game Over?Aug 04, 2022
- Unbroken v0.2.74 - The Path to SuccessAug 03, 2022
- Unbroken v0.1.32 - First ContactAug 03, 2022
Leave a comment
Log in with itch.io to leave a comment.