Unbroken v0.2.74 - The Path to Success
Dev Diary: Update 2
“Good morning, pilot!
The aliens certainly didn’t seem to appreciate what you did to their recon drones. If we can trust the latest reports, they are now about to send armed battle ships our way. You will have to deal with moving targets that make use of their cannons. The government was pretty explicit about their expectations. Seek and destroy all approaching ships. There is no room for failure here. If we mess this up, we will have to deal with a global panic. This is your time to shine, soldier! I expect a written report after your operation.
You are still here? Hurry!”
Evangeline M. Cromwell, CEO of the Unbroken Organization
Release Notes
Enemy AI
- alien ships move along curved paths
- alien ships fire at an interval
Gameplay
- whenever all aliens have been destroyed (or evaded), a new wave spawns
Tech Talk
Moving objects along a straight path
The problem of moving objects along a straight line can be achieved by using polynomials and parametric equations.
Consider a straight line defined by the two points P0 and P1.
Let P0 be the start point and P1 be the end point of the line:
- P0 = (x0, y0)
- P1 = (x1, y1)
We can now manipulate the parameter t to determine the values of x and y along this line.
- x(t) = (1 - t) * x0 + t * x1
- y(t) = (1 - t) * y0 + t * y1
- where 0 <= t <= 1
Or in other words: while t increases from 0 to 1, P travels from P0 to P1.
- P(t) = (1 - t) * P0 + t * P1
This means:
- at P(t = 0), the point P would be exactly on P0.
- at P(t = 1), the point P would be exactly on P1.
- at P(t = 1/4), the point P would have travelled exactly 1/4 of the distance between P0 and P1.
Now we can use Unity’s game loop and do the following each frame:
- set t to be the time that passed since our ship began moving from P0 to P1
- calculate the position P(t) of our ship, according to the formula above
As a result, the ship travels along the line in a smooth animation.
Moving objects along a curved path
Moving objects along a curved path can be achieved with Beziér Curves. Beziér Curves are using the same principle as before. We move points along straight paths while t increaes from 0 to 1. But this time we are not limited to 2 points or 1 line respectively. Instead, Beziér Curves are defined for any number of control points, where the number of control points N represents an N-1 degree polynomial. More controls points means more complex curvatures.
Earlier:
- we had 1 line (black) defined by N=2 points (P0, P1)
- we watched how P traveled along that line as t increased.
Now, imagine:
- we have 2 lines (red) defined by N=3 points (P0, P1, P2)
- we can watch how
- Q0 travels from P0 to P1 and
- Q1 travels from P1 to P2
As before, we can calculate the points Q0 and Q1 as follows:
- Q0(t) = (1 - t) * P0 + t * P1
- Q1(t) = (1 - t) * P1 + t * P2
Now we are back at the original problem, which we already know how to solve.
- We have only 1 line (blue) defined by N=2 points (Q0, Q1)
- We can watch how a new point R travels along the blue line as t increases.
We can calculate the point R as follows:
- R(t) = (1 - t) * Q0 + t * Q1
The route that R takes is depicted by black dots in the animation. As you can see, the result is a smooth curve, following the 3 control points P0, P1 and P2, which is exactly what we wanted to achive. We can move our ship along an arbitrary path, using this technique.
This video on Youtube helped me understand this problem.
Implementing all of this in Unity would be a lot of work. Luckily, it has already been implemented and provided as a free asset by Sebastian Lague. Therefore I am using his Path Creator for my project.
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.1.32 - First ContactAug 03, 2022
- Unbroken v0.1.16 - Endless SpaceAug 03, 2022
Leave a comment
Log in with itch.io to leave a comment.