Enemy From Different Angles- Game Dev Series 39
Objective: Create different enemy movement.
Feeling too easy about our game? It might be a good time to raise up the difficulty.
We can change the movement of enemy to make it harder to be shot.
I have got some ideas about the enemy movement. It will moves in 2 way.
- Normally go straight down.
- Move diagonal to the right or left randomly.
When the enemy is out of scene area, teleport to the opposite on x-axis.
We will not choose which movement that the enemy has. Just make it random.
Open the Enemy script and create an integer variable as movement ID.
Since we have 2 types of movement, we can make it choose 1 randomly in Start().
In the Update(), we can use switch statement to definite the way of movement by ID.
Then we can extract the original movement into NormalMovement(), and create a new one: DiagonalMovement().
Within the DiagonalMovement(), we will have 2 ways of movement: To the left & right. The only difference is on x-axis, one should be negative integer.
We can simply change the random ID to control the x-axis.
And also some little changes on switch statement.
In this switch statement, 1 & -1 will be sent to DiagonalMovement() method. Means we need to use the ID to our method too.
Then we need to add some lines of code to make it flies back when out of boundaries.
These lines used to be in the movement method, now should be a good time to extract as new method.
Then we need to called this method both in NormalMovement() and DiagonalMovement().
All done! Now your enemy should be more tricky to hit!
Next: New Firing Powerup