Skip to content

Waves n pathing#2

Open
kyleamazza wants to merge 22 commits intomasterfrom
waves-n-pathing
Open

Waves n pathing#2
kyleamazza wants to merge 22 commits intomasterfrom
waves-n-pathing

Conversation

@kyleamazza
Copy link
Owner

Okay, in summary:

  • Added a WaveConfig scriptable object that contains some of the data for a wave.
  • Added each WaveConfig to the GameManager via a WaveSpawner script which simply loops through the waves once via coroutines.
  • Added AnimationControllers with Animations for the pathing of a wave, which is included into the WaveConfig.
  • Made a generic object pooler class which runs off a single instance, and generates multiple pools that can be accessed via tags.
  • Made a BulletEmitter script which...emits bullets...(my idea with this was to be able to separate bullet patterns from the enemy itself, allowing bullets to spawn independently of enemies, or something like that. It's easier to explain with a picture, but I can explain when we talk again, plus I have questions about how to approach this)

Questions that I have:

  • Is there a better way to animate pathing? I know that it can be done via math equations, but I wasn't sure how to combine mathematical functions to make more complex paths (i.e. straight line - into circle - into sweeping arc)
  • Is there a better way to use animation to do pathing? The way I did it feels a little bit inexact (I used curves mostly).
  • How can I spawn multiple waves at the same time? I figured I could just have multiple WaveSpawners running coroutines concurrently alongside each other, but I wasn't sure if that was a good way to go.
  • Right now the bullets just fire straight down, attached to the enemy instance. I wasn't sure how to approach more intricate patterns/multiple bullets firing off of a single enemy in multiple directions. I was thinking of having multiple BulletEmitters nested under a parent object, nested under an enemy instance. Then, the BulletEmitters simply fire off bullets in a direction, but can rotate or translate or do weirder stuff. But I feel maybe I'm overthinking/overcomplicating it.

Thanks for helping out so far, sorry this past week or so has been pretty slow with adjusting to school schedule and trying to change all of my classes.

…ips. Current Animators and clips are temporary
private void ActivateBullet()
{
GameObject nextInactiveBullet = GetNextInactiveBullet();
GameObject nextInactiveBullet = bulletPool.GetPooledObject("Bullet");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings in c# are allocated in dynamic memory - or the "heap". Every time you call this function and pass in a string like "Bullet", it'll create a new string in memory and allocate it onto the heap. Over time, this will call the garbage collector to run, which is an expensive action. Since this function will be called numerous times, it will be best to pass in a cached variable of the string.

int numberOfEnemies = waveConfig.NumberOfEnemies;
for (int i = 0; i < numberOfEnemies; i++)
{
GameObject obj = enemyPool.GetPooledObject("Enemy");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my other comment about passing in strings


private void Fire()
{
GameObject nextInactiveBullet = bulletPool.GetPooledObject("Bullet");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about string passing

@thomastianlu
Copy link
Collaborator

My main thought of how the current wave pattern works is that it gets the job done, but can get hairy if we start to think about future proofing it.

Pros:
Tight control and precise animations can make for some very beautiful enemy waves.

Cons:
If you want to reposition an arc, but keep the same pattern, it gets tough to do
It may not be reuseable with other enemies if we decide to make new ones.
If we decide to add abilities that reposition the object - e.g. knockback - we probably can't do it

Personally I would like you to take a look at how to make it work with math. You can probably make it equally pretty - if not better with simple math and easing. To answer your question about complex paths, it would look like the same equations we learned from school:

You can set X as time, use Time.time or Time.deltaTime

Straight Line: y = slope * x + (y-Intercept)
Circle: y = sqrt ((radius^2) - (x - xCenter)^2) + yCenter
Sweeping Arc - this can be a circle, a parabolic equation, or whatever depending

Depending on what pattern you want, you can just google an equation and plug time into X and you should get your movement patterns. You probably shouldn't use animation pathing for a number of reasons - but the main one is that it's inflexible, and if you need to make changes later, it will be much harder.

Multiple Waves:
You can do this a number of ways - you could do it with multiple wave spawners, but they'll need to be tied to a single wave manager so you can properly manage them.

Bullets:
I think you should approach this by which direction the bullet fires out of. You could have a Vector2 in your enemy and set it to fire in different directions by looking at where that Vector2 is pointing. You can then pass it into the bullet that's firing and put that in it's movement update.

I think overall you'll need to think about how can I make this clean with the least amount of code possible. Remember that when you make something work in code, you're only halfway there since you have to clean it up or see if you can make it better. Always be thinking if you're going to be confused or kicking yourself in the future when you're coding things.

I know this isn't meant to be a long project, but it's good to think in this mentality. Let me know if you have any questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants