Posts

Showing posts from April 19, 2018

Unity Project 4: Ball platformer game (Code Explained)

Image
'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, acti

Unity Project 4: Ball platformer game

Image
Finished game displayed in the scene view. Scene view Assets Uses Rigidbody so that the ball can use physics (Gravity) therefore it doesn't fall through the ground. The 'Rolling Ball' script is attached to the ball which adds force to the ball. Ball Inspector Scene view displaying the invisible cube object which can be used as a trigger for an event. Scene view When the console prints 'COLLIDED', the ball has collided with a specific object (Invisible cube). Console Message The invisible cube that is attached to the 'Trigger' script. When an object does not have a mesh renderer, the object becomes invisible as we cannot see it due to it not having a mesh. Cube Inspector Field of view changed, so that the ball can be seen from a slightly different angle. Follow target script also attached allowing a first person type view of the ball as the camera is set to follow the ball's movement. The camera can be moved so tha