George Asiedu

Adding to the physics in unity topic we have two methods we can call that effect our game objects. In my previous example i used OnTriggerEnter

Which activated the destroy game object instruction. this works because both objects have colliders components attached.

in the unity documentation is it explained like:

Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.

the other OnCollisionEnter can be used when collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. For example if we wanted to trigger a finishing line to trigger the end of a race. Gameobjects can pass through each other and an event can take place.

--

--

Using in physics in unity is done through applying the component “Rigidbody” to your game component. With this attached it will be able to respond to gravity and be able to collide with other game objects.

Rigidbody component

To help with the collision of two objects you also add a collider. this can be a box, capsule and other types

--

--

in most shoot’em up style games there is some control to the rate of fire. The example above would suit a rapid fire power up but what if we want to control it or slow it down.

to control the rate of fire we will need a variable to recognise it

--

--

To make our cube/player be able to shoot, we will add another game object and name it Laser. The laser will be made into a prefab which can be re used when called or instantiated.

Gameobjects that are shown as a bluebox are prefabs:

--

--

For a beginner like me being able to learn to code has been made easier to understand by the use of “pseudo code”. This is the act of writing out your code in plain English to put across as a function.

Pseudo code example

This section of code reads as an if statement for the player. When the player reaches one side reset to the other side. In code this is what it looks like:

--

--

To be able to make our game we need to be able to make our player do actions. These actions must be given names and identified within the script of our player. Anything in games is a sort of variable assigned to an element whether it is a skill or an attribute.

For example making our player move we had to decide how we declare the speed:

Here “speed” has been made as a Float variable, this means it is a decimal and the number must end with an f.

Ever variable has a name, data type, size and value

We can declare the name.

The main data types are Integer, Float, String and Boolean

Integer = being a whole number

Float = a number with a decimal point

String = a sequence of characters

Boolean = true or false

--

--

To get our player moving within our scene I have applied a script to a cube. This script will hold all the actions related to the cube named “Player”

opening the Player script within an IDE will allow us to enter code to make our game and communicate within the unity menus

--

--

The Unity interface is a versatile one with many windows. They can be manipulated in many ways. here is the default layout:

Default Layout

in the left of the screen you can switch through some pre-set layouts. I like to be able to see as much information as possible when developing and have been suggested a more productive layout which is liked out like:

--

--