Last week was a busy week, focusing on gameplay improvements! A bunch of physics bugs were destroyed, and the gameplay and input overall feels way more responsive and clean.
Problems to Solve:
- Input isn't set up to be platform agnostic
- Input and ball jumps not able to be customized for input swipe lengths.
- The ball floats in place when sticking to a moving object.
- Bunch of weird physics bugs
The Solutions!
1. Make input Platform agnostic
I want to eventually put this game on mobile, Steam, and Switch, so focusing on a single aspect ratio won't do. The input was initially set-up on a single 16:9 landscape. That doesn't factor in different phone or tablet aspect ratios. What is a developer to do?
Well, I was most of the way there. I updated the Gameplay manager to take in the screensize values and divide my touch start and end positions by that. Boom, bam! Problem solved.
Now no matter the screen size or shape, players will have similar input results and swipe sizes.
2. Adjust Swipe input and ball trajectory calculations to be tunable
This one was fun. I wanted to be able to adjust the length a player needed to swipe to get a pre-set minimum and maximum power for ball launches. It took a bit of mathing, but managed something that works!
What I'm doing is:
- Clamping the initial input from 0,1 to prevent any values over 1 from being calculated (eg. a swipe greater than the screen height)
- Setting the clamped number to a maxLaunchInput variable if it is higher. This allows me to only require a tunable swipe length to reach max power.
- InverseLerping the new clamped number between 0 and the max input. Gives me a position between 0 and the max input to adjust the launch power between min and max.
- Lerping THAT between min and max launch power.
I can adjust my variables for the input min/max, and the launch power min/max however I like, and its giving me the desired result. Something to clean up later, but it works!
3. Make sure the ball doesn't float when sticking to moving objects.When I stick the ball to a surface, I'm freezing its position and velocities until acted on again. This causes the ball to float when it licks against moving objects like my new rotator gizmo.
I love the solution for this, because it's simple, dumb, and effective. I still freeze the physics/positions, but I also re-parent the ball to the moving object it collides with. Whatever animation is playing on the moving object, the ball will follow.
I just needed to make sure the Animate Physics flag was set on the animator, otherwise spooky stuff happened.
4. Stabilize physics on the ballI occasionally encountered really weird physics bugs, like the object getting stuck in corners, clipping into geometry, and sometimes rolling away through the air. Sometimes this caused player input to lock and you'd have to restart. Booooo!
I investigated for a while, and found a very elegant solution that solved a ton of my physics problems.
On collision with an object, I added freeze position and rotation logic. On jump, I unfreeze. This little velocity freeze function has made gameplay so much smoother and predictable.
The result of all the hard work is a much smoother, more enjoyable to play experience!
Next up for gameplay improvements is to adjust my launch angle detection to ensure that players can't launch the ball horizontally and make it roll instead of jump.
Stay tuned!