Dunking


November 28th, 2024

Hello! I am back with my first blog post in two months! I've been working on the game steadily, but I haven't been making time for blog posts. From here on, I won't be covering every new feature I create, just the major ones I feel are worth discussing. Today, I'll be breaking down a major mechanic for my game, dunking. A video will be attached at the end if you want to see the result!

Overview

There are two components to dunking, a jump pad for the player (I won't have a jump button in the game), and a basket for them to dunk on. This system depends on an ITag interface I made, a wrapper class for an unordered set of strings. I've added this interface to my AABB class.

JumpPad and Basketball Goal Classes

The JumpPad class is an object with a special tag JUMP_PAD on its AABB. The CollisionType is set to Trigger so the player isn't blocked. The collider settings are set up in the class' Init function:

The BasketballGoal class is a similar story, with a few minor differences:

I shrink the collider and raise it so it is where the actual goal is, like so:

 

Player Dunk

The Player class is where the magic happens. In Player::OnCollisionBegin, If the player collides with the jump pad, they'll start ascending, while they'll begin descending if they collide with the basket:

 

The PerformJump function will lerp the player's position to a certain height, which is hard-coded for now. The camera will also stop following the player while they're jumping:

The EndJump function does the opposite. It moves the player back to their initial height, adds to the score, and undoes the actions made by Perform Jump:

And that's all the code! Now let's see it in action…

Demonstration

Conclusion

This implementation builds off systems I already made, so it didn't take long to make. In my next post, I'll be covering another gameplay mechanic, Stances.

Thanks for reading,

Jamari

Leave a comment

Log in with itch.io to leave a comment.