Creating a Da○saba○ber (No. 3)
![]()
table of contents
Due to internal training sessions and other things, it's been a while since my last update.
Good work everyone.
This is Matsuyama from the Systems Development Department.
We are pleased to present the third issue of "Creating a Da○saba○bar," which began abruptly in the previous issue
The first issue is here ↓
Issue 2 is here ↓
In issue 2, we implemented three types of weapons that players can use (maximum level 3).
In issue 3, we will implement zombie ecology (generation and movement) and leveling up using collected experience points.
Zombie Creation
From a game system perspective, it seems to be a survival-based game, so I think a requirement is to increase the number of zombies that appear as time passes.
Therefore, I have prepared two types of generation processes.
① One enemy appears at regular intervals (short intervals)
② A large number of enemies appear at regular intervals (long intervals) (waves)
① is designed to make it easier to gain experience points little by little when your initial weapon level is low.
② is designed to allow you to level up your weapons while running away from large groups of enemies, and to provide the exhilarating feeling of entering genocide mode once your weapon level is high enough.
Both events should spawn at a certain distance from the player's location.
Additionally, coroutines should be used to handle the waiting period.
The process for generating one at a time is as follows:
private IEnumerator spawnBase() { const int MAX_BASE_ENEMYS = 50; const float spawnRadiusMin = 8.0f; const float spawnRadiusMax = 10.0f; const float spawnInterval = 1f; var waitTime = new WaitForSeconds(spawnInterval); while(true) { // Spawn so that there are always MAX enemies if(enemies.Count < MAX_BASE_ENEMYS) { // Player position Vector2 playerPos = playerController.GetPlayer().Position; // Determine placement radius float r = UnityEngine.Random.Range(spawnRadiusMin, spawnRadiusMax); // Determine placement angle float angle = UnityEngine.Random.Range(0, 360); // Spawn spawn(playerPos, r, angle); } yield return waitTime; } else { yield return null; } }
- Every second
- Up to 50 units
- Located 8.0 to 10.0 units away from the player
- Randomly generated at an angle of 0.0 to 360.0 units from the player -
Instantiated using the spawn function
. This is how they are generated.
Wave (②) has the same basic implementation as ①.
The coordinates, angles, and generation are repeated for the number of zombies to be generated. The
number of generated zombies is gradually increased, with more zombies generated in the second wave than in the first.
Only that part is excerpted.
// Determine the number of spawns from the wave (maximum 100) float spawnNum = Mathf.Min(wave * 10, MaxSpawnNum); // Place at equal intervals float angleRange = 360 / spawnNum; // Player position Vector2 playerPos = playerController.GetPlayer().Position; // Spawn for(int i = 0; i < spawnNum; i++) { // Determine the placement radius float r = spawnRadiusMax + UnityEngine.Random.Range(-1.0f, 1.0f); // Determine the placement angle float angle = angleRange * i; // Spawn spawn(playerPos, r, angle); }
It looks like this

Zombie Movement
This is the impression I got from watching the original: - It's slower than the player - It moves towards the player - Its tracking ability seems low , so the processing should be something like this: ① Find a vector pointing towards the player ② Move in that direction for a certain amount of time ③ Return to ①
private void walk() { // Walk this.transform.localPosition += new Vector3(walkInfo.course.x * WalkSpeed * Time.deltaTime, walkInfo.course.y * WalkSpeed * Time.deltaTime, 0); // Update timer walkInfo.timer -= Time.deltaTime; // Reset the timer when it falls below 0 if(walkInfo.timer < 0) { walkInfo.timer = walkInfo.interval; // Timer walkInfo.course = (walkInfo.player.Position - this.transform.localPosition).normalized; // Walking direction } }
There is no stopping, so all you have to do is run Update() every frame
It looks like this

Experience points
I'm not sure if "experience points" is the correct term, but it's that stuff you collect to acquire weapons and level up.
When you defeat a zombie, it's placed, and when the player approaches, it's collected.
The Enemy class generates an Exp object through the ExpController class when the death animation finishes.
Generation process
public void OnAnimationEnd() { // Destroy once death animation is over if (status == Status.Dead) { expController.Spawn(this.transform.localPosition); Destroy(this.gameObject); } }
The collection is done by calculating the distance to the player using the Vector2.Distance function, and moving objects within the threshold towards the player's coordinates. This is also processed in a coroutine
Collection process
private IEnumerator move() { var elapsedTime = 0f; var startPosition = transform.localPosition; while (elapsedTime < 1f) { var targetPosition = playerController.GetPosition(); elapsedTime += Time.deltaTime * MoveSpeed; transform.localPosition = Vector2.Lerp(startPosition, targetPosition, elapsedTime); yield return null; } Destroy(gameObject); }
It looks like this

Weapon Level UI
It's that thing where you get a weapon or level up after accumulating a certain amount of experience points.
We've already implemented the level control for each weapon in version 2, so we'll make it controllable via the UI.

- Gray background: Panel
- Weapon icon: Button
- Text and stars: Text
By combining these, you can create something that looks like it.
Here is the finished product
When you combine this implementation with the first and second issues, it will look something like this

it's starting to look pretty good, don't you?
Next,
player HP management
, a time limit
, and magnets
to complete it.
The entire project is available on GitHub, as usual.
This blog post contains a lot of source code, so if you want to see the whole thing, please check it out there. I hope it
's helpful in some way.
BeBe Survivor
Well, that's all for today
The first issue is available here ↓
https://beyondjapan.com/blog/2024/02/survivor/
Issue 2 is here ↓
https://beyondjapan.com/blog/2024/03/survivor2/
7
