Unity Project 4: Ball platformer game (Code Explained)

'RollingBall' script allows the ball to be moved by the player using the 'W, A, S, D' keys. When any of these buttons are pressed then the ball will move in the direction that has been set in the code. When the space key is pressed, the ball jumps and again uses force of the object's Rigidbody.

Moreover, the script adds force to the Rigidbody of the object making the ball a little bit more difficult to control. The value can be edited in the scene view.

RollingBall script

The script rotates the two cubes which look like a windmill.
Transform.Rotate allows the arms to rotate around the same axis.
The speed is set in the scene for the windmill.

RotatingWindmill script


When the ball collides with whatever object this script is attached to (invisible cube) then the word 'COLLIDED' is printed in the console.

This trigger can be used for many different aspects in a game. This may include: spawning enemies, losing/gaining health, activating a door to be opened/closed, playing music/sounds etc.


Trigger script

Follow Target script allows the camera to follow the ball (Target). 
An offset has been applied so that if wanted the ball can be seen slightly ahead of view, making it easier to control.


FollowTarget script

Comments

Popular posts from this blog

Logo Design

Bootstrap Template