top of page
Search
Writer's pictureNg Wei Shun

Zombie Shooter Devlog #2 : The Enemy

Hello fellow reader, welcome to Zombie Shooter DevLog #2. Today I’ll be writing about Player and Enemy interactions.

In the previous DevLog, I implemented shooting controls and the movement of the bullets. Now, I am going to work on creating enemies complete with movement, attack, and health programming.

The Enemies are closer than you think

Similar to how the player rotates towards the cursor in the previous DevLog, the enemies will rotate towards the player relative to their own position. On top of that, they will move towards the player using the same Vector2 value, at a set speed.


movement = (playerPos - enemyPos).normalized;

rb.MovePosition(rb.position + movement * speed * Time.fixedDeltaTime);


It is important that the speed value uses a Public access modifier, at least during development, so that I can tweak the value easily inside Unity itself to balance the game.

They’ll chase you, they’ll rip you open


As soon as an enemy ‘collides’ with the player (their collision boxes are touching), the enemy will execute the attack function. The attack function will reduce the health of the player by one (I’ll talk more on health later) every 1.5 seconds. The attack function will only work if the enemy is colliding with the player for the full 1.5 seconds, though, I think it would be better that the enemy can still deal damage if the player is still within a certain range. I’ll work on implementing that if I can figure out how.


private void OnCollisionStay2D(Collision2D collision)

{

if (collision.gameObject.CompareTag("Player"))

{

attackDelay -= Time.deltaTime;

if (attackDelay <= 0)

{

playerHealth.reduceCurrentHealth(1);

attackDelay = 1.5f;

}

}

}

The Enemy (Types) is gathering


Like I previously mentioned, I want my player experience to mimic that of Alien Shooter. In the game, not only will the player be swarmed by Aliens, they are swarmed by DIFFERENT TYPES of Aliens, such as the Spiders with faster speed, or the Robot Lizards that shoot lasers.


Both the enemies and the player have a health manager. They manage the unit’s max health and current health. The unit’s health will be reduced when taking damage, and destroyed if their current health is less than or equal to 0.


void Update()

{

if (currentHealth <= 0)

{

Destroy(gameObject);

}

}

With the default enemy created, I can easily make a different version of this enemy by ‘Creating Prefab Variant’. I can then tweak the appearance and values that this variant uses. I used this method to create a red enemy that is faster, and also a blue enemy with more health, that is also larger in size.

And just like that, we can now face off against our tough undead enemies. However, we are no match against them with just a pistol. I’ll be giving the player a rifle and a shotgun in the next DevLog.


Until next time!

5 views0 comments

Recent Posts

See All

Comments


bottom of page