How to Roll a Ball - Devlog#09


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, inside you have a prefab of a ball and couple useful scripts to help you move it.

Now I'm not gonna talk about it because you can find plenty of resources and informations on 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

Devlog about Jelly Shader


Movement

For any platformer movement is crucial, metrics are very important and need to be controlled via scripts to adapt to various situation.

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 because 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 active 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 is a script to lerp the Player's rigidbody 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 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

Jumping should be fun and consistent.

The first thing you need to do if you use gravity is increasing 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 having 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 a main feature because of the chaotic nature of the physics.

Here is the code for it:

It uses a wallAngle float to check if the normal hit raycast is above, so you don't wall jump on too steep wall.


Feedbacks

Now this step seems superficial, but it is very important to give your game good feedbacks to the player.

Simple things you can add, vibration if your game supports gamepad (it should) !

And again Lerp saves the day. impulseMagnitude is the collision force of your character.


You can add visual feedbacks 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.



Extra Things

I've noticed that player complained about the camera behaviour 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. (Will do a devlog about it too)


I've added an effect of speed when you reach a certain speed, the effect also change the camera fov to apply a dolly zoom.

I got really good feedbacks 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 other 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 to some players or devs so that you can get honest feedbacks.


Conclusion

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 feedbacks to give the player a good sensation !


If you like my devblog, I would be happy if you wishlisted Crumble on steam.

Thanks !


© 2023 by Brute Force Games.

  • Twitter Social Icon
  • Facebook Social Icon
  • Icône social Instagram
  • YouTube Social  Icon
  • LinkedIn Social Icône

If you have any questions Mail us at:

bruteforcegamesstudio@gmail.com