Make Your First 3D Game Fast – Block Maze Racer

Make Your First 3D Game Fast – Block Maze Racer

Venturing into designing 3D games can be intimidating. I mean, it is another entire dimension of complexity. This game is simple by design. The player is an awesome happy block with a great haircut, I might have designed the 3D model, the level is an ever changing maze, and the goal is to not hit the walls. Starting with simple objectives and assets allows for us to more deeply explore the physics, object interaction and camera manipulation that makes the massive billionaire franchises so fun to play. All the code and assets are linked below, everything is free to use and build with. Make an awesome game and have fun!

Plain Text of the PlayerScript.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerScript : MonoBehaviour
{
public Rigidbody rigid;
public float moveForce = 50.0f;
public CameraScript mainCamera;
private int level = 1;
public Text levelText;

public GameManager gameManager;

void Update()
{
if (Input.GetKey(“up”) || Input.GetKey(“w”))
{
rigid.AddForce(0, 0, moveForce * Time.deltaTime, ForceMode.VelocityChange);
mainCamera.SetDirection(“up”);
}
if (Input.GetKey(“down”) || Input.GetKey(“s”))
{
rigid.AddForce(0, 0, -moveForce * Time.deltaTime, ForceMode.VelocityChange);
mainCamera.SetDirection(“down”);
}
if (Input.GetKey(“right”) || Input.GetKey(“d”))
{
rigid.AddForce(moveForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
mainCamera.SetDirection(“right”);
}
if (Input.GetKey(“left”) || Input.GetKey(“a”))
{
rigid.AddForce(-moveForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
mainCamera.SetDirection(“left”);
}
}

private void OnTriggerEnter(Collider collider)
{

if (collider.tag == “Exit”)
{
PlayerRespawn();
level = level + 1;
moveForce += 20.0f;
gameManager.NextLevel();
}
levelText.text = level.ToString();
}

private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == “Obstacle”)
{
// Ground Color
Color[] options = { Color.white, Color.black, Color.green };
Color newColor = options[Random.Range(0, options.Length)];
GameObject.Find(“Ground”).GetComponent<Renderer>().material.color = newColor;
level = 1;
moveForce = 25.0f;
PlayerRespawn();
}
levelText.text = level.ToString();
}

void PlayerRespawn()
{
transform.position = new Vector3(12.25f, 1.5f, -13.5f);
transform.rotation = Quaternion.Euler(-90, 0, 90);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *