As some development practice on the side I have also been working in Godot, and was inspired to make a roll-a-ball game similar to Hamsterball or Marble Blast. At first this was as simple as creating a Rigidbody3D node for the player, and attaching a sphere mesh and spherical collision shape to it. I also threw on a texture of a billiard ball, both for fun as well as to give me some visual context as to how fast the ball will be rolling.

I then had to create a camera that would orbit around the ball with what is known as a “gimbal” movement. Rather than manually setting the camera’s position, I instead created an empty node as a child of the player that would automatically follow above the player. I would then attach the camera as a child of that at a certain offset away from the ball. The rotation of the parent node according to the camera can then be done at the centre, and the offset of the camera (i.e how “zoomed out” it is) can be set to whatever I want on the fly.

I also attached a “spring arm” to the camera, meaning it will move closer to the player if colliding with a wall or floor, preventing the camera from clipping inside of them.
Now that the nodes were added I had to add some code to rotate the camera’s origin node according to movement of the mouse. I am using GDScript for this project, as I do not need the performance and data management-related benefits of C# for a simple game concept like this so far. I first added a script to the player with the following code to let the camera “orbit” around the player.

Then came adding code to make the player move. In Marble Blast Ultra the player’s marble rolls to move in a snappy fashion, but also has some control in the air from a direct force pushing it. To recreate I find the intended direction the player wants to travel in by getting the rotation of the camera & multiplying it by the input direction, so a “forwards” input will always be straight ahead for the ball from where the player is facing.

Then I apply a force in that direction, and add angular velocity for the “rolling” effect.

Now I can roll the ball around just fine! However the ball does feel somewhat “slippy”, and simply increasing the friction could lead to unintended results like being able to roll up walls. I solved this problem by checking if the intended direction is opposite (or near enough to it) to the velocity the ball is going in, we slow the ball down quickly so it can switch directions in a much snappier fashion. It only does this when the ball is grounded to simulate “grip”.

This works! The movement feels really responsive now.

After making this basic concept, I was inspired to expand on this concept and have my game for this assignment be a physics based game, with a rolling mechanic as the primary method of traversal. However, I may not have the player always control a perfectly spherical ball, and therefore I will continue to use the angular velocity method to allow objects of any shape to be able to roll.
Leave a Reply