Day 2 – Stumbling Time
The first stumbling block came in the form of colliders and triggers. If there’s an easy way to have both a trigger collider and a physical collider I haven’t found it yet. I was loath to give up my ability to shove the enemies around, so I ended up spending a bit longer than I should messing with parenting and other things. Eventually I went with the simple option that I should have started with – just set the crowbar collider as a trigger and let it pass through things. While cool, the physical interactions aren’t essential to core gameplay so they can wait until I’ve done a bit more reading.
I hit several issues adding enemy spawning, none severe but the extra minutes add up under severe time pressure. First my script wouldn’t run, which appears to have been caused by a naming mismatch. Once it was running I wasted a bit of time trying to invoke a coroutine incorrectly. Finally, I messed around too long trying to add spawned enemies to a list and as children, basically because I wasn’t sure of the type of a returned object and didn’t check the example or documentation as soon as I should have. I wasn’t trying to do anything too unusual here, and I can put all of these issues down to simple inexperience.
I know that with a bit of practice, all these problems will start to look very naive. They already seem at least a little silly as I’d already seen some of the solutions in the tutorials at least once, so some of the wasted time was unnecessary. Since wasted minutes are such an issue in this project, I’ll put the lessons here to ensure that for the remainder of the project I don’t waste more than a few seconds on issues I’ve already encountered:
- Make sure script and GameObject names match before attaching the script.
- Use StartCoroutine(IEnumerator) to fire up coroutines.
- Instantiate(GameObject, …) returns an object castable to GameObject.
- Access the script attached to a GameObject using gameObject.GetComponent
- Set parents by setting transform.parent to the parent GameObject’s transform.
I didn’t have time to get scientists spawning, but that should be trivial after working out all the issues with the enemy spawning script. I wasn’t planning to remove the physical effects of enemies colliding with the crowbar, so I want to get that back at some point – either with extra colliders or just by manually changing velocity in the collision event – but other things are higher priority at the moment. The important thing for now is that I can now bludgeon head ticks to death to take out the frustrations of development snags!
|Enemy death (red == dead).|
|Spawning enemies with the spawner as parent.|