GameDev Blog: Goblin Rules Football #26: Swing Animation and Ground Tiles!

I decided to ignore all of my “Next Steps” from my previous post, and decided instead to work on completely different things, first things first I made a swing animation. Look at it!

Wow! Whoa! Great swing, great follow through. You love to see it. Also, it looks like a few pixels are missing in the “hit” frame, but that’s actually just white “motion” sprites that don’t show up on a white background until they are over a green goblin…

The other thing I really wanted to fix was when the ball would show behind or in front of objects like trees. At first I thought this would be easy, just set the right sorting layers and whatever. But, I then ran into the issue that I need the ball to be in front of the tree when the “shadow” shows as further down the screen compared to the tree, and behind the tree when the shadow is higher up. I was thinking of dynamically setting the ball sprite’s pivot point to be where the shadow sprite was, but that seemed weird and possibly complicated to then deal with the position of the ball sprite.

So, I avoided that path and then started to try and dynamically change the sorting layer number of the ball and tree sprites. Then I ran into the issue when there are a bunch of trees in a group and the ball is flying through the middle. Lower the sorting the layer of the trees “behind” the ball, and then move up the trees in “front” of the ball, but then the tree that’s in front is now in front of trees that it shouldn’t be in front of, so I’d have to find every tree object that is lower on the screen than the “in front” tree and update their sorting layer as well… and that seemed complicated and also computationally expensive to recursively try and find every sprite that is front of a sprite that you’re moving to the front…

And then, I remembered, “sprite masks.” What I ended up doing was just adding a Sprite Mask component to a tree/object, and then when the ball sprite is supposed to be “behind” the tree, I turn the Sprite Mask component on. If the ball is in front, then the Sprite Mask remains off.

Anyway, that all works and took an embarrassingly long time to figure out. Well, actually, it doesn’t work entirely. The trail component of the ball still doesn’t stay in front of trees like the ball does, and that’s because my version of Unity (2021.3.10f1) doesn’t support sprite masks for trail renderers. Apparently, a newer version of unity supports it, but I don’t want to upgrade right now and potentially break everything… so for now the trail just would render quite correctly. Oh well.

The final thing I did, and one I also spent a lot of time on, is making ground tile sprites. I made Fairway tiles, Green tiles, Rough and Deep Rough tiles, and then Sand and Water trap sprites. They look, fine, I guess. Look and see for yourself.

I kind of just winged the sprite tiles for this. I think they look fine? One issue is that the fairway and green tiles look fairly “clean” while everything else is pretty noisy looking. Kind of looks off all together. Oh well. Maybe I will fix that? Also, not 100% happy with the edges and my attempts to “blend” the edges together so they don’t look so angular. Maybe in the future I will redo it all. Maybe not. I need colliders on the tiles as that’s how the ball detects what type of surface it is on and uses that to calculate how to bounce/roll, and I had to set a custom physics shape for each tile so they’d line up correctly without overlaps, and that was a lot of tedious work! Not looking forward to maybe having to do that all again!

Anyway, here’s a video of everything!

Next Steps…

The next thing I really want to do is find a way to make it so each tile can contain individual data, specifically any slope data aka hills and stuff. I already have a way for the game to detect a slope from an object and then apply that slope to the ball’s rolling trajectory (but not yet to bounces…), I just need a way to make it so that data is stored per tile. Right now, I can only really set all the tiles in a given ground type (green, fairway, etc.) to have one slope value. I’ve found some tutorials here and here that I haven’t checked out yet. I believe they use “scriptable objects” which is a Unity thing I still haven’t used yet. I’ve heard they’re quite useful. I should probably check them out. My plan was for arrows to appear above sloped tiles to display to the player what the slope direction and magnitude of the slope is. I never liked how Golf Story did it’s slopes, and then Sports Story was released just before Christmas and does exactly what I was planning to do (all the bugs and performance issues, as well as the lack luster new sports, make Sports Story a bit disappointing for me but whatever I’m still playing through it and having a good time). Great minds think alike? Or just more blatant copying for me? I guess that’s for Sidebar Games’ lawyers to figure out.

Smell ya later, nerds!