Making Da○Saba○ Bar (No. 2)
I hope I didn't have to wait that long this time.
This is Mr. Matsuyama from the System Development Department.
We bring you the second issue of ``Making a Da○Saba○ Bar,'' which started abruptly from the last time.
Click here for the first issue↓
In the first issue, we even displayed the player enemy field and implemented the ability to move the player.
I think the appeal of "Da○Saba○Bar" lies in the exhilarating feeling of destroying large numbers of zombies with a wide variety of weapons, so I'm planning to implement weapons in the second issue.
Weapon type
However, it would take too much man-hours to implement all of the large number of weapon types, so I think I'll narrow it down to about three types for now.
① Shotgun (default weapon)
② Brick
③ Guardian
Around here.
As usual, I will search for images from Undead Survivor that can be used as resources and use them.
① The shotgun itself was accurate.
② There are no bricks. I have all the farming tools, so I'm going to throw a plow.③
There are no guardians on discs either. Let's spin the "kama"
shotgun
Identify requirements.
① Fire in the player's direction (direction of travel)
② The number of bullets fired increases depending on the level
③ The firing interval becomes shorter
depending on the level ④ The firing range increases depending on the level
⑤ Zombies are nearby
⑥ The bullet will fly in the direction of ① for a certain period of time and disappear.
hits a zombie, it will not penetrate.
It happened unexpectedly.
① to ⑤ are the process up to firing (Weapon_1)
⑥ to ⑦ are the bullet process (Bullet)
Therefore, we will separate them into classes.
An image of generating a bullet with Weapon_1, and the fired bullet moves and disappears by itself.
Basically, get the player's orientation from the Player class and determine the reference line of fire.
All you have to do is rotate his line of fire ±n° based on the starting point (player coordinates) according to the number of bullets, and you can scatter the bullets in a fan shape.
I prepared these parameters for control.
// Bullet firing interval (3 levels) private readonly float[] interval = { 1.5f, 1.25f, 1.0f }; // Bullet firing range (3 levels) private readonly float[] range = { 4.0f, 6.0f , 8.0f }; // Number of simultaneous launches (3 levels) private readonly int[] simultaneous = { 1, 3, 5 }; // Launch angle (5 directions: depends on the number of simultaneous) private readonly float[] angle = { 0, 10, -10, 20, -20 };
Regarding ⑤,
let the EnemyController class search for nearby zombies.
If so, the vector between the player coordinates and the zombie coordinates becomes the ray.
The scattering of bullets is the same as above.
After firing a bullet, the Bullet class moves autonomously.
If you move and hit a zombie, you will get a collision check, so you can create a state where it will not penetrate by deleting your own object.
Even if it doesn't work, it will still be deleted after a certain period of time.
That's how the shotgun is completed.
Here's the finished product↓
・Level 1
・Level 2
・Level 3
Brick (like)
① Throw it upwards
② Fall in an arc at a certain height
③ Delete it when it finishes falling (outside the screen)
④ Penetrate even if it hits a zombie (up to 3 zombies)
⑤ Number of throws depending on the level Increase. (Throw at different times)
The class composition will be similar to that of shotguns.
Generate Plow with Weapon_2. After that, Plow itself will fly in a parabola.
The position of the enemy does not particularly matter.
The biggest problem is the formula for drawing a parabola.
After searching for a while, I found this wonderful site.
If you want to fly an arrow in a parabolic shape (ignoring 2D gravity),
it's perfect. Thanks to Hatena Blog.
This is a formula that calculates the coordinates on the Bezier curve specified by the start point (p0), vertex (p1), and end point (p2).
Create a coroutine by adding the process of rotating the direction of the plow by 180° near the vertex.
///<summary> /// Draw a parabola ///</summary> ///<param name="p0"> starting point</param> ///<param name="p1"> Vertex (relative coordinates)</param> ///<param name="p2"> End point (relative coordinates)</param> ///<returns> coroutine</returns> IEnumerator Throw (Vector3 p0, Vector3 p1, Vector3 p2) { float distance = Vector3.Distance(Vector3.zero, p2); float speed = 0.3f; float t = 0f; while (t <= 1 && isAlive) { float Vx = 2 * (1f - t) * t * p1.x + Mathf.Pow (t, 2) * p2.x + p0.x; float Vy = 2 * (1f - t) * t * p1.y + Mathf .Pow (t, 2) * p2.y + p0.y; transform.position = new Vector3 (Vx, Vy, 0); t += 1 / distance / speed * Time.deltaTime; // t from 0.4 to 0.6 during, gradually rotate 180° if (t > 0.4f && t < 0.6f) { float angle = Mathf.Lerp(0, courseGoal[course], (t - 0.4f) / 0.2f); transform. rotation = Quaternion.Euler(0, 0, angle); } yield return null; } Destroy (this.gameObject); }
* Fixed because p1 and p2 needed to be relative coordinate values (2024.3.22)
Then specify p0 to p2 when generating Plow.
You can make it look like this by adding random numbers to the height of the vertices and the width from the start point to the end point to create some variation.
Here's the finished product↓
・Level 1
・Level 2
・Level 3
Guardian (scythe)
The one that spins around the player.
① Rotates around the player
② Number increases as the level increases
③ Does not disappear even if hit by a zombie (penetration)
Yeah. It has the fewest requirements.
Made the same way. Generate Sickle class with Weapon_3.
Just place them at equal intervals depending on the number of pieces you want to place and rotate them at the same speed.
The coordinates (offset values) of circular motion can be calculated using trigonometric functions.
Since it will follow the player, all you have to do is add the player's coordinates.
With these definitions in place,
// Radius public const float Radius = 4.0f; // Rotation speed (seconds) private const float RotateSpeed = 270f; // Rotation speed (seconds) private const float SpinSpeed = 1080f; // Angle (angle to determine position ) private float rotateAngle = 0.0f; // Angle (rotation) private float spinAngle = 0.0f;
All that's left is to process it with the framework.
void Update() { // Increase the angle (revolution) rotateAngle -= RotateSpeed * Time.deltaTime; // Increase the angle (rotation) spinAngle -= SpinSpeed * Time.deltaTime; // Convert the angle (revolution) to radians float rad = rotateAngle * Mathf.Deg2Rad; // Convert angle (rotation) to radians float spinRad = spinAngle * Mathf.Deg2Rad; // Update position Vector2 pos = player.Position; transform.position = new Vector3( pos.x + Radius * Mathf.Cos(rad), pos.y + Radius * Mathf.Sin(rad), 0.0f ); // Update rotation transform.rotation = Quaternion.Euler(0.0f, 0.0f, spinAngle); }
Along with the circular motion, the sickle itself is also rotated.
Here's the finished product↓
・Level 1
・Level 2
・Level 3
Debugging UI
Create a debugging UI to check the operation.
- Levels 1 to 3 can be set for all weapons
- Weapon 1 is level 1 by default
- Weapons 2 and 3 are not acquired at the beginning
Add Legacy Buttons, etc. to make it quick.
That's all for this month
That's all for now.
I think I was able to implement it quickly thanks in part to the sites I referenced.
It's fun to create things with Unity, even at the mini-game level.
By the way, the full attack state looks like this.
Next time
・Collect zombie ecology
/experience points and raise weapon level
I hope I can implement this.
As usual, the entire project is available on GitHub.
I hope this will be of some help to you.
BeBe Survivor
Well, that's all for now.