How to roll a ball in your game, like the unity roll a ball standard asset, but better!
The standard asset
Jokes aside, Unity offers a really good starting point for you to make your own rolling ball game.
It comes with the standard assets pack with any 3D Unity project, you have a prefab of a ball and couple of useful scripts to help you move it.
Now I’m not gonna talk about it because you can find plenty of resources and information in the Unity manual.
What I’m gonna talk about is how to make it more juicy and responsive to the player inputs.
If you haven’t read about my early devlogs about physics I strongly recommend you to:
Devlog about Physics optimization
For any platformer movement is crucial, metrics are very important and need to be controlled via scripts to adapt to various situations.
To move the ball in the direction you want (in front of the camera) you use the rotation of your camera:
The reason why you use rotation instead of direction like in the standard asset is that you don’t want to go up or down as well, so to prevent slowing down your ball when you’re looking at the ground you use the Y-axis rotation of your action camera and assign it as an angle to the inputs.
If you don’t have a world up like in space, for instance, you will use the direction instead.
Something to implement as well as a script to lerp the Player’s rigid body drag to its velocity. So when you go faster you get less resistance to the air and you keep going faster. It makes the player feel the acceleration and doesn’t feel like a rigid max speed value.
You can use lerp too instead of a curve in the editor.
Here’s the difference without and with:
Another small thing that I thought about in Crumble is a script to slow down the player speed if there are no inputs registered. So the player won’t slide off the platform or won’t overshoot a distance because he was too slow to give the right inputs. A simple condition with input == 0 and a velocity lerp should do the trick.
Camera movement and player animations play a great deal in the feel.
Jumping should be fun and consistent.
The first thing you need to do if you use gravity is to increase the value by times 2 to 10 because you don’t want the player to feel like it has no weight.
The perfect jump for my game was to have a very quick boost upward and have a small window of low gravity at the end so that you can decide where to go.
To help with that you can lerp the jump force with time and a curve:
This will change the way the jump will behave based on the shape of the curve.
The vector up is there because I wanted to have a use for wall jump in the game even if it’s not the main feature because of the chaotic nature of the physics.
Here is the code for it:
It uses a wall angle float to check if the normal hit raycast is above, so you don’t wall jump on a too steep a wall.
Now, this step seems superficial, but it is very important to give your game good feedback to the player.
Simple things you can add, vibration if your game supports the gamepad (it should)!
And again Lerp saves the day. impulse magnitude is the collision force of your character.
You can add visual feedback such as trails and jump Fx like the one I have on the upper gif.
And don’t forget to add a nice sound effect to it.
I’ve noticed that the player complained about the camera behavior in Crumble’s demo and I changed it to not collide with physics but only to hide it!
This can be done via shader and raycast. (I will do a devlog about it too)
I’ve added an effect of speed when you reach a certain speed, the effect also changes the camera for to apply a dolly zoom.
I got really good feedback about the speed in the game so I intend to work more on that.
The trail that leaves the ball behind him on objects and grass plays a good role in the feel too I think, and it’s fun for the player to be able to leave a trace and interact with the environment in a funny way.
It’s important to have a good level design too, I suggest you study another 3D platformer that uses the same mechanics as you do. Then fine-tune the metrics by playtesting your game A LOT, don’t hesitate to share your game with some players or devs so that you can get honest feedback.
Rolling a ball is easy in Unity, but to make it roll nicely takes time.
The main thing you should be after is the feel of rolling around and jumping, once you have the mechanics down, you test it to have better metrics and when you’re finished, polish it with extra feedback to give the player a good sensation!
If you like my devblog, I would be happy if you wishlisted Crumble on steam.