USING UNITY IN MAKING AN ANIMATION OR GAME



So I started to make a simple game using Unity Editor. It's my first time to make such thing, A GAME! Kinda sounds nuts, but yeah I did make one. This is for my Intro to Game Design course and I'm happy to say that I had made a game, and I'm proud of if. . .

This game is in 2D. The concept is to add an object or obstacle to make it move, by creating it in Unity Editor.

First, we have to make a project in Unity Hub, but make sure you have downloaded the needed and updated Unity Editor (the latest version is Unity 2020.1.4 as of now). Then once the software was opened, select projects and click new, then choose 2D as our template, name it as you like. 



As the UI of Unity appears, look for your assets down the projects table, or drag them to assets. The assets must consist of our Image for Player, and also it's sprites (later including the Player Controller).



As an alternative to the previous step you could also use the main menu and select Assets Import New Asset.



Once done, proceed to dragging your player image and sprites on the scene. Look at the inspector window and add component. But make sure the player image has appeared in the hierarchy window (in its file name yet) later you may edit it as "player". 



Add Rigidbody 2D and Boxcollider 2D to "player" (as previously named after the file name). Once done, add another component as "PlayerController" by creating new script then set it to C#. Then it will open at your MSVisual Studio (or any code editing software).



This one is kinda short and compact, but it works. . . So I add it as the player controller for the game. So you'll just add a few parts of the code in between of the pre-coded text, most of it I looked from the internet. 

Apply this code:

using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody2D rb2d;
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
rb2d.AddForce(movement * speed);
}
}

Once applied, you may now play our obstacles. As same as the player image "player". We also need to add components to each of them. Adding Rigidbody 2D and Boxcollider 2D. But the difference is it doesn't have a script or a player controller because this will be our obstacle or decoys. In Rigidbody 2D you may adjust the mass and gravity of the selected object. Then the Boxcollider will put field or barrier in the object selected.



Then add a platform underneath your obstacles or decoys. Add Rigidbody 2D and Boxcollider 2D. In Rigidbody, set the gravity to zero. And on Boxcollider, adjust its size to your preferred size.



Lastly, add player object's Rigidbody 2D the speed of that object, which will make our player movable, and disabling gravity by putting zero on its gravity scale which will prevent the player to infinitely fall in the game.



Now try to click play and see if there's an error, if it's unable to render or play. If not, you may now try controlling it by arrow keys or WASD keys. See if the speed is enough, and also if the obstacle or decoy where in place. Hold the key until it hits them, if they did not moved by the hit, then edit back if Boxcollider is added (same with the obstacle and decoy).


Watch the video below:




If everything is in sync and playable. You now have made a simple 2D game using Unity Editor.

As observation, the player acts as the vehicle which we can control. It has its speed and hardness and mass. Like in the Newtons 1st law of motion, every object will remain at rest or in uniform motion in a straight line unless compelled to change its state by the action of an external force. 

Same with that, the spaceship (Player) is at rest as well as the obstacles or objects. Once we move the spaceship towards to obstacles or objects, it pushes them away at the direction were the force is to (in which the spaceship was moving as a straight line or moving towards to obstacles or objects). 

So it just reacts the same as in the real world added that the objects are affected by gravity. It simulates the mass and gravity plus force and speed, which works in real life. And games have the potential to make realistic simulators or animations. 

As on my hands-on experience, even though it's my first time to make a game. Thankfully I made it work at least as expected. I look forward on studying further in Game Design. And on how to make better games in the future.

Comments

Popular Posts