Update v0.3.1: Bullets and Stuff
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
Get Goblins versus Mechs
Goblins versus Mechs
Status | In development |
Author | Lowtek |
Genre | Shooter |
Tags | 2D, run-and-gun |
Languages | English |
More posts
- v0.2.1 - Enemy AI FoundationsFeb 14, 2022
- First Dev Builds Up!Feb 11, 2022
Leave a comment
Log in with itch.io to leave a comment.