Boss Fight: Stage 2— Movement

Ryan McCoach
5 min readAug 17, 2021

--

For the movement of the boss, we are going to have two phases: Boss with shield and Boss without shield. Lets first create the boss movement when the boss has its shield.

Boss with Shield Movement

We are going to create 3 empty objects that are going to be WayPoints or destinations for the Boss to move towards.

In the Boss script, we will need the Transform of these WayPoints and we are going to store them in an array with a SerializedField attribute.

Lets assign these WayPoints in the Inspector, so we now can access them in the script. A variable is going to keep track of what waypoint we are currently moving towards.

When I first attempted the Boss moving towards a waypoint, the Boss would move towards it and just pass it. This may be because the waypoint transform position is being passed over during the Update or the between the frames being drawn. We are going to create a variable that will represented a zone or radius, so if the position of Boss moves into this zone we can detect it.

In the Update, we check the distance between the current waypoint position and the position of the Boss and if it less than the waypoint radius, then we can change the current waypoint by picking a random between 0 and length of the waypoints array length.

For actually getting the Boss to move towards one of the waypoints, we can use Vector3.MoveTowards, which requires the current position of the thing that is moving, the destination, and the movement speed.

Now that we have the Boss moving between the waypoints, I want it to pause certain amount of time before moving to the next waypoint. We are going to need a bool variable to track if the Boss is current moving of it is stopped. We will set isMoving to true at the Start.

If isMoving is true, we will use the MoveTowards line and when the Boss is within the waypoint stopping radius we set isMoving to false have it stop it from running the MoveTowards line. Since we want a pause we are going to need a coroutine.

In the coroutine we pass in the amount of time we want to wait before setting isMoving back to true.

When the Shield Generators are ALL Destroyed we are going to increase the speed of the Boss every time it takes at hit when the Shield is still active.

As I am working the this, from time-to-time, I will change variable or method names to make it easier to read. Changes made at this point…

  1. _shieldVulernable = _hasShieldGenerators
  2. IEnumerator WithShieldMovement () = IEnumerator MovementDelay ()

The wait time at each waypoint dependents on the state of the shields. If the shield generators are still there will we have a different wait time before moving than when ALL of the shield generators are destroyed.

Boss Without Shield Movement

When the Shield is destroyed we will we added a few more waypoints to move between.

We also need to know when the shield is destroyed, so we are going to create a bool variable _isShieldDestroyed.

We can use this variable to change what waypoints the Boss can move to by restricting the random range from 0–2 when _isShieldDestroyed ==false and when _isShieldDestroyed == true, the random range is from 0 to the length of the array (0–4).

Using this new variable we can also adjust the wait time before the Boss moves. Keep in mind the guns will be firing when it is stop so those time to be different during each of these stages.

Summary

  1. When the Boss has the shield generators it will move between three waypoints randomly with a different wait time.
  2. When ALL of the shield generators are destroyed, but still has the shield the Boss is still randomly moving between the three waypoints. Each time the shield takes a hit, its speed will increase and the wait time is different than before.
  3. When the shield is destroyed the Boss will now randomly between 5 waypoints and it still going the max speed from before and its wait time is different than before.
  4. The Boss will be firing when it is not moving.

This was a little disorganized, but this shows I need to start working on pseudocode before coding. Cheers!

--

--

No responses yet