“Bounce” is a physics based platformer where a bouncing ball is moved left and right by the player towards the goal. The ball maintains a low bounce on regular floors and is propelled higher by contact with trampoline objects.
SpriteShapes are used to render the floors, the trampoline, start and goal objects, and the bouncing ball. Cinemachine is used to keep the ball in view with smooth camera movements.
The floors are SpriteShapes with a flat white fill texture. This allows us to change the fill color from the editor GUI. For the outlines of the floors we use GIMP to create a circle that fades smoothly to tranparent, dice it up with the Unity sprite editor and assign the multiple sprites to the SpriteShape profile corners.
This gives us a nice smooth outline around all the floor shapes.
A directional light is used to cast shadows onto the background – a textured quad. After some failed attempts to get the meshes generated by the SpriteShapes to participate in the shadow calculations a simple workaround was found: each floor SpriteShape is paired with one or more game objects each with a quad mesh and renderer component.
Start, goal & trampolines
These three object types use essentially the same SpriteShape profile: an arrow texture with black border and white fill, and a solid white texture for one side of the shape. The different types of objects are given unique colors through the Unity editor.
The ball is also rendered with a SpriteShape but no corner images are used and the tangent mode of each spline point is set to continuous.
A soft-body mechanics simulation is run each frame to give the ball some squishiness on contact with the boundaries. Each node in the simulation corresponds to a point in the SpriteShape spline and a node in a mesh component. The spline takes care of drawing the outline relatively smoothly with no gaps, while the mesh component casts a shadow onto the background quad. After each simulation step the new data is propagated to the spline and mesh.
Making contact with a trampoline causes the ball to bounce higher and higher, while contact with regular floors causes the ball to bounce less and less until it settles into a small perpetual bounce. The ball also bounces off side walls.
Cinemachine is used to follow the ball around the level. The default settings cause the camera to oscillate slightly when the ball is bouncing idly. A small increase in the dead zone height is enough to fix the problem.
The other parameter that was changed is called 'Bias Y'. It seems that reducing this parameter forces the camera to move downwards along with it's target. In Bounce, this setting gives the player a slightly better chance of seeing what is coming up below when falling under gravity. The following screen captures show the differences.