What is Game Engine ?
What is Game Engine ?
A game engine is a software framework used to create and develop video games. It provides the essential tools and technologies needed to build a game, allowing developers to focus more on the gameplay, mechanics, and design rather than building everything from scratch. Game engines typically handle various aspects of game development
Populare Game Engines,
Unreal Engine
Unity
Godot Engine
CryEngine
GameMaker Studio 2
Construct
RPG Maker
Amazon Lumberyard
Cocos2d
Gamebryo
Let's crete an FPS Game
Game Engine : Unity
C# Scripts ,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class playercontrol : MonoBehaviour {
public float speed = 3.0F;
public float rotateSpeed = 3.0F;
void Update()
{
CharacterController controller = GetComponent<CharacterController>();
transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
Vector3 forward = transform.TransformDirection(Vector3.forward);
float curSpeed = speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameracontrol : MonoBehaviour
{
public GameObject player;
public float xSensitivity = 10;
public float ySensitivity = 10;
public float smoothing = 0.4f;
public int min = -60;
public int max = 60;
private float mouseOffsetY;
private float mouseOffsetX;
private float xtargetRotation = 10;
private float ytargetRotation = 10;
void Update()
{
mouseOffsetY = Input.GetAxis("Mouse Y") * ySensitivity;
ytargetRotation += -mouseOffsetY;
ytargetRotation = ytargetRotation % 360;
ytargetRotation = Mathf.Clamp(ytargetRotation, min, max);
mouseOffsetX = Input.GetAxis("Mouse X") * xSensitivity;
xtargetRotation += mouseOffsetX;
xtargetRotation = xtargetRotation % 360;
transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(ytargetRotation, 0, 0), Time.deltaTime * 10 / smoothing);
player.transform.rotation = Quaternion.Lerp(player.transform.rotation, Quaternion.Euler(0, xtargetRotation, 0), Time.deltaTime * 10 / smoothing);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class shoot : MonoBehaviour
{
public float damage = 10f;
public float range = 100f;
public Camera fpsCam;
public Text countText;
private int count;
void Start()
{
count = 0;
SetCountText();
}
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
target Target = hit.transform.GetComponent<target>();
if (Target != null)
{
Target.TakeDamage(damage);
count = count + 1;
SetCountText();
}
}
}
void SetCountText()
{
countText.text = "SCORE :- " + count.ToString();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class target : MonoBehaviour {
public float health = 50f;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
Destroy(gameObject);
}
}
Let's create a Car Game
Game Engine : Unity
Let's go through the process of creating a simple car game in Unity:
- Open Unity Hub and click on "New Project."
- Select the 3D Template.
- Give your project a name and click Create.
- In the Hierarchy window, go to "Create" > "3D Object" > "Plane." This will serve as your ground or terrain.
- Rename the Plane to Ground.
- To give the plane a color, create a Material and apply it to the plane.
- Import a Car Model from the Unity Asset Store or use a free car model from an external source.
- Drag and drop the car model into your scene.
- Rename the car model in the Hierarchy to Car.
- Select the Car GameObject in the hierarchy and add the Rigidbody component. This will enable physics interactions for the car.
- Add a Box Collider to the car to handle collisions with other objects and the ground.
- Create a new Scripts folder to organize your game scripts.
using UnityEngine;
public class CarController : MonoBehaviour
{
public float speed = 10.0f;
public float turnSpeed = 50.0f;
void Update()
{
float move = Input.GetAxis("Vertical") * speed * Time.deltaTime;
float turn = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
transform.Translate(0, 0, move);
transform.Rotate(0, turn, 0);
}
}
- Save this script and then drag and drop it onto the Car GameObject.
5. Setting Up the Camera Follow:
- Add the Main Camera as a child of the Car Object.
- Create a simple follow script to make the camera follow the car smoothly.
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float distance = 10.0f;
public float height = 5.0f;
void LateUpdate()
{
Vector3 newPos = target.position - target.forward * distance + Vector3.up * height;
transform.position = newPos;
transform.LookAt(target);
}
}
- Save this script and drag and drop it onto the Main Camera.
- In the Main Camera GameObject, drag and drop the Car Object into the CameraFollow script.
6. Running the Game:
- Click the Play button to test the game.
This is a basic process for creating a simple car game, and you can improve and expand it further by adding features as outlined in the Improvement section below, based on your requirements.
New Tutorials Coming Soon !
. . .