Player -Color, Movement @ Unity Part 1

Player, Enemies, Car etc — Nothing exists when Unity Editor opens for first time, these are what called Objects more precisely Game Objects.

To define these Game Objects in Unity, one has to create these objects from scratch — whether it’s 2D or 3D.Creating Prototype of these objects and put life into it — like color , movement, boundaries where they exists, move & perform some kind of action / motion .These are called characteristics and behavior of these objects — created using Scripting APIs using C# or UnityEngine APIs.

Here take an example of Unity 3D Object Capsule, which is Game Object.

Note : This Game Object along with others like Main Camera, Direction Light have certain things in common — all having TransformIt’s used to store and manipulate the position, rotation & scale along X,Y & Z direction along with this having unique properties.

In order to Prototype Player, let’s create Capsule 3D Game Object & applying some color to it — creating Materials folder under Projects and adding new Material & applying Albedo (RGB and Transparency) that defined under Mesh Renderer of Game Object as shown below.

For Movement- for the Player, one has to create a new C# Script and attached it to the 3D Object here Player as show below

When you double click on it — opens in Visual Studio, that having class Player inherit from MonoBehavior that UnityEngine Provides having the Start and Update methods.

In Unity Transform have properties position , consider an example where Player moves from the current position to the new position using the c# script below.

Similarly Transform having Translate method — give life for the movement of the Object i.e., right, left, up and down using Vector3 translation parameter passed to this method. i.e, public void Translate(Vector3 translation)

Consider few examples :

a. Moves to right.. Its been called once per frame

b. Its same as moving to +1 X axis right (1 meter/frame in real world) transform.Translate(new Vector3(1,0,0));

c. Its same as moving to -1 X axis left (1 meter/frame in real world) transform.Translate(new Vector3(-1,0,0));

d.To move 1 meter per sec incorporate using Time.deltaTime i.,e Time.deltaTime represents the time that passed since the last frame. transform.Translate(Vector3.right * Time.deltaTime);

e. To move 5 meter per second , multiple by 5 (eg moving speed =5 )i.e., Multiplying the moveSpeed variable by Time.deltaTime ensures that the GameObject moves at a constant speed every frame. transform.Translate(Vector3.right * 5 * Time.deltaTime);

More Importantly, adding these behavior , characteristics in more controlled manner are defined using Variables — see you in Part 2 .

@GameDevHQ-Day 5…

I am a passionate technologist with a strong aptitude for new skills that includes Exploring and Learning Unity 3D Scripting APIs… !!