itch.io is community of indie game creators and players

Devlogs

Update v0.3.1: Bullets and Stuff

Goblins versus Mechs
A browser game made in HTML5

The very word “ballistics” is complicated, isn’t it? Needless to say this was a pretty intimidating mechanic to have a go at.

I was able to get some basic ballistic action on the bullets going just by using Rigidbody2D.AddRelativeForce(). No special calculations or other maths required. Thanks Unity!

Still, I did run into some tough bugs while coding the bullets and figured I should give this devlog thing a go to share.

There’s a lot of tweaking and tuning to make bullets feel correct. My big issues were all timing: the timing of bullet instantiation (and its initial state), the timing of updates to its position, the timing of the collision itself and the timing of its destruction. All of these little, tiny, thorny corners caused me a days worth of energy before I had something that was even acceptable as a bullet mechanic.

Here’s what I learned in a nutshell:

  • Raycasts are a perfect tool for the task
  • Layers …take advantage ffs!

I was coding some behavior for projectiles so that when they hit a character, they self destruct (and eventually kill said character). As I implemented it though I had to decide whether the collision would be detected on the player or the bullet.

Now my first instinct is always to just get the feature working and refactor the design later. But in this case it really nagged me that I was coding towards a solution that would make every object that touched a bullet have to check for it. And this felt wrong from the start. So the next question was: how do I make the bullet responsible for this check?

The builtin collision events won’t do (OnCollisionEnter and others) because they check that other colliders have touched this collider. I needed to check the reverse, that if a bullet touches anything else it should self-destruct – ya know, as bullets do.

So Physics2D.Raycast was exactly what I was looking for. It’s in game and I still need to tweak and polish its performance. But its always a sublime feeling when you get the perfect tool for the task!

Files

  • goblins-vs-mechs-v0.3.1-pc.zip 23 MB
    Version 1
  • goblins-vs-mechs-v0.3.1.zip 5 MB
    Version 1
Download Goblins versus Mechs
Leave a comment