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:
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 …