Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Interesting challenges

A topic by WayfarerGames created Aug 13, 2019 Views: 159
Viewing posts 1 to 1
Submitted (1 edit)

I thought I'd post some of the fun little challenges I've faced so far during the jam, just in case it helps anyone or people are interested! 


1. Outlining the player/enemy models
The player and enemies really don't stand out so well on their own no matter what I did, so I thought an outline might serve well. I tried a great many things, none of which scaled down to this resolution particularly well! Then I remembered an old pixel art trick for giving a 1 pixel width thick outline - copy the image, make it entirely the colour of the outline, and paste it 4 times and offset it by 1px in each direction. Turns out that works just fine in Unity! I render the player/enemies/anything with an outline to a separate 64x64 render texture, then render the same thing with a pure white unlit material to a separate render texture, then use 4 offset RawImages on my canvas pointing to that same "outline" render texture, and voila! I'm using camera culling to make sure I'm not rendering the objects/outlines 3x, but other than that it's a pretty straightforward fix. This does have a couple of downsides: I'm rendering everything that has an outline twice, and I can't really have things rendered in front of the player/enemies. However, neither of those particularly matter, as everything is incredibly simple geometry and the "rails shooter" gameplay means nothing really has to be rendered on top of the player!

2. Targeting enemies
I knew it would be really annoying to play if the cursor didn't lock onto enemies properly. I originally tried a raycast from the mouse position through the camera, but that required the cursor to be too close to the enemy, and caused it to jump around too much. Unity has spherecasting built in, though, so all I needed to do was change `Physics.Raycast` to `Physics.SphereCast` and it pretty much just worked. Another really useful built in tool is `RectTransform.WorldToScreenPoint` - using that is how I get the UI elements placed at the correct positions.

3. A better way to signal events
I was originally going to spawn enemies/end levels/etc using collisions, but that required too much manual positioning. I'm using a Cinemachine path to describe the player's path, so switching everything over to just comparing positions on that path seemed like it would work pretty well. And it does! Events are now signalled without extra collision detection! Using serialized unity events to hook things up to positions, I basically just place an object along the path and attach it to the `OnSendEvent` function, just like a UI button. This is how I handle enemy spawns, dialog and level complete. 

I think that's all I have for now, if you want to know more detail/how I did something else, just ask!