This is a list of every issue I ran into and either solved or still don't know how to do it or what is wrong:
Problem #1 - Moving things forwardI don't know how to move an object "forward", this is a major problem that is going to continually haunt me in projects so I better learn this. Normally I would just use move in x direction * movement speed * time.deltatime each update call. But when you're not playing a side scrolling game where you are only moving right or a shmup where you are only moving down, it gets more complicated.
How do you even quantify an abstract of "the direction you are moving in" when it could be left/right/down/up or any 360 degree direction?
Solved? - No.
Workaround? - Sorta. I know how to use Vector2.MoveTowards to set waypoints and have things move to them. I also similarly know how to direct set the coordinates for objects to move to such as in my shmup where I say "move down until Y axis ____ and then move left & right between X axis __ and X axis ___. But this is pretty limiting and doesn't cover all the movement situations I'll need. For example what Sage is saying about raycasting. I've never done a raycast before, I assume it's similar to a boxcast which I've done in my platformer by boxcasting "down", but with a raycast how would I know what direction to even cast the ray? Forward ahead of you could be any 360 direction.
I tried transform.position = but that just teleports things and I tried Vector3.Moveright and that didn't work for moving my car from the left side of the screen to the right on the X-axis.
I definitely need some help on figuring out how to just make a blank scene and drop an object and then make a script that says move from the left side of the screen to the right. You would think putting "transform.position = new vector2(transform.position.x+1, y) * movement speed * time.DeltaTime would do it, but I swear that didn't work for my car.
Problem #2 - Multiple MovementsI wanted my UFO's to circle instead of just moving forward, or at least move in a square. I tried putting in 4 waypoints and having a waypoint counter to tell which waypoint it was at and when it reaches that waypoint to increase the counter and then the next if counter == kicks in and it moves to the next one. For some reason it would just move to the first waypoint and stop. I'm sure I could fix this with some debugging.
Solved? No. But can fix this on my own with time debugging.
Workaround? Nah, I just gave up and had it move in a straight line to one waypoint.
Problem #3 - NPC random movementThis mostly ties into #1, I think if I could figure out how to tell an object to pick a direction and move forward in that direction I'd be ok. The turning and changing directions is the easier part.
Solved? Sorta.
Workaround? Yeah, honestly if you check out the game the NPC random movement looks pretty ok. I think my solution of using MoveTowards and just setting the waypoints as RNG that changes every 3 seconds to a different spot on the map, and changes on collision with anything works pretty well. It does just congregate most NPCs in the middle of the screen though as the RNG waypoints tend to draw NPCs towards the center of the screen.
Problem #4 - NPC Spawning with screen border collisionSo here's the thing. I don't like how NPCs just magically appear in the middle of the screen when they spawn. Especially since they can RNG spawn ON YOU and instantly kill you with no warning.
Ideally I'd have liked to have some spots outside the map where the NPCs funnel in from and then spread out from there. The problem is that if the screen border is a collision that keeps the NPCs from wandering off the screen, it would also prevent them from entering the screen. So I'd need like a one way door to let NPCs in, and I have zero idea how to do that.
Even if I knew how to do that, I'm not sure how I'd make the NPCs initially come in and then spread. I
think a solution would be to set their initial waypoint as the center of the stage arena for the first 5-10 secs after spawn and then start RNGing the next waypoint every 3-4 seconds. That would probably work.
Solved? - No. Maybe if I could make one way doors and had some time.
Workaround - Nah, just left them teleporting in.
Problem #5 - NPCs spawning on you and instantly killing youI tried to work around this in multiple ways and wasted some real time on this issue to make the game more fair. I tried turning off the NPCs collider for the first 3 seconds after spawn to give some invuln time of hitting the player if they spawned too close to the player. The problem being that this also meant you couldn't kill NPCs with objects for the first 3 seconds which was incredibly unsatisfying when you opened a street fault line and half the NPCs take no damage and just float over it.
Solved - Nope, good luck player! All's fair in RNG.
Workaround? - Nah, not really sure how to do this. You need a collider to be able to trigger/collide and NPCs need to hit stuff to die but not the player. Maybe some complicated code where the player death on collision isn't coded on the player script but on the NPC script reaching over to the player and then can make it if colliding tag is the player and time since spawn is less than 3 seconds, do nothing, else send DIE() to the player. That's a little complicated and with time I could probably do it but feels like it'd be a lot of work.
Problem #6 - ParticlesMy particles were fucked.
Solved - Yes. Turns out somehow when I added a particle system to the scene it attached to a car object, meanwhile I was working with a different particle system and the two were causing interaction problems. I never knew there was one on the car because the sorting layer had its particles hidden behind the scene. Only when looking at the car object did I see it and removing it fixed the particles.
Problem #7 - SFXMy SFX were iffy if I tried to play them.
The way I would do SFX is I would put the SFX as an audio source on the object and then in the object's script it would say
[SerializeField] AudioSource SoundEffect
then in the code on collision would say
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
DRIVE = true;
SoundEffect.Play();
}
}
Then I would drag the audiosource on the object into the public field for sound effect. And this worked for my car and UFOs.
But for my NPCs I was spawning, I did this exact same thing to play SFX on collision before they died. I even put a waitforseconds coroutine in to give a few seconds before they were destroyed in case it was destroying them before the SFX could play. It never worked. When I put the SFX on the car to play on collisions with non-player it would play.
The NPC prefabs included the audio source on the NPC as well as it slotted into the serializefield for sound effect, these NPC prefabs were spawned. I...still don't know why the SFX wouldn't play.
Solved? No.
Workaround Yes. I ended up putting the death sound effect on the bloodspurt particle effect game object. When NPCs are hit they instantiate the deatheffect gameobject which is the bloodspurt particle so the SFX plays on awake. I just wish I knew why the NPCs won't play their own SFX.
This is the code on the NPCs.
[SerializeField] private AudioSource ADD
And
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("NPCKILLER"))
{
ADD.Play();
Explode();
StartCoroutine("Death");
Destroy(this.gameObject);
}
else
Newwaypoint = new Vector2(Random.Range(-2.8f, 3.2f), Random.Range(-1.7f, 2.76f));
}
Problem #8 - UI stuff with carrying over score between stage and game over screen and implementing it into the text on the game over screen.
Solved - Uh, sorta.
Workaround - Yes, I basically ended up carrying the game over screen's UI panel & text with the gameManager as setactive(false) on the stage screen and it becomes setactive(true) on the game over screen.
I'm pretty sure I could get around this with better coding, where the game over screen UI text has a script that calls a method on the gamemanager instance to get the score int and then display the text + score int. I just needed to organize my game manager better from the start. Ended up carrying a lot of random stuff on it between the stage and the game over screen.
Problem #9 - Button thing.
Solved? - Yes. Explained above. Fixed once I figured it out.
Problem #10 - Built it wrong!
I was speedrunning this project so I didn't organize my assets at all or even put my build order scenes in the right order and the main menu was scene 3. Learned the hard way after building it that game always starts on Scene 0! Always put your main menu on Scene 0 lol
Solved? - Yes, I knew this but forgot. Good reminder.
Problem #11 - Not using the SFX I wanted
I was lazy and under time crunch and didn't want to start searching for free use SFX for the exact sounds I wanted (I wanted a cheering SE on happy win screen and a sulking sad SE on sad win screen and I wanted NPC death effect to be screams). So I just used whatever I had from like 30 SFX from one pack I had.
Solved? - Sorta. The SFX I ended up using were semi-decent. Can fix this if I just spent some time finding the right SFX or even making my own like making a few screams and pitch modding them on my phone.
OverallI think that was it. I definitely could've done things better and smoother. The plan originally was to have multiple levels with different objects like the Statue of Liberty which starts walking and crushes people and wrecking balls and open manholes and stuff. With NPCs spawning in increased amounts over time and maybe having a timer to make it more a certain death over time try to get as many kills as you can thing.
The two major issues that screwed up the development of this game concept were making NPCs wander and not get stuck crowded up on the wall borders and the SFX playing on NPC death. If not for those, probably could've made this pretty smooth in 4-5 hours and had time to add a few more stages and some more polish.
If I can figure out the basic "how to move things in a direction" I think I'd feel more confident about trying another small shot project like this and doing it better. Maybe keep trying one screen small games over and over until I can make one smoothly in a few hours to get me back feeling confident about coding and not awful about it.
The button issue was literally just the UI canvas text covering the button. Like the text didn't cover it, but the text rect was double the size with a lot of blank space and the blank space covered the UI button. I guess I could also fix this by making the UI button the child of the text so it sits on top.
There's a couple of easier fixes; the generic one, is anything you don't want to block raycasts, put it on the Ignore Raycasts physics layer.
The UI specific one, which is common enough it has its own dedicated fix, is on any UI element, there's a raycast target checkbox on the image component - just uncheck that
Time for me to look up what a raycast is!