Corona Maze Runner

This tutorial implies the creation of a maze with Rhino Grasshopper and alternatively with Blender, than exporting and preparing the set in Unity. In Unity a NavMesh with IA will be implemented. Then a few scripts will allowed to set up a game experience that will be extended in Augmented Reality.

Let’s start in Blender

The Maze Generator can be found here

https://github.com/elfnor/mesh_maze

Other kind of maze can be found here https://github.com/Gorgious56/MazeGenerator/releases creating a maze is not obvious. Results can be surprising and rewarding https://imgur.com/a/6u13JSG

A prior version was here : https://elfnor.com/maze-any-mesh-in-blender.html

The Blender Maze is prepared and painted into Unity

The ground is replaced by a Terrain Asset

The size fits to the actual ground, it could have been enlarged

It’s been sculpted

And painted

Additional pack can be added to enrich the environment

Add a mesh collider for the walls

Preparing the Maze for IA

It has to be Navigation Static

In navigation add 2 layers

The terrain is Walkable

Wall are not walkable

Ready to bake

The blue colour indicates that it worked

To test the camera is moved to an upper position.

To test IA, add a NavMesh component

And this script

using System.Collections;
 
 
using System.Collections.Generic;
 
using UnityEngine;
 
using UnityEngine.AI;
 
public class MoveTarget : MonoBehaviour
 
{
 
public NavMeshAgent nmAgent;
 
void Update()
 
{
 
//If the player has left clicked
 
if (Input.GetMouseButtonDown(0))
 
{
 
//Get the mouse Position
 
Vector3 mouse = Input.mousePosition;
 
//Cast a ray to get where the mouse is pointing at
 
Ray castPoint = Camera.main.ScreenPointToRay(mouse);
 
//Stores the position where the ray hit.
 
RaycastHit hit;
 
//If the raycast doesnt hit a wall
 
if (Physics.Raycast(castPoint, out hit, Mathf.Infinity))
 
{
 
nmAgent.SetDestination(hit.point);
 
}
 
}
 
}
 
}

Test by clicking anywhere to see what path is used.

To explore the Maze we will use Third Person Controller – Basic Locomotion FREE

Drop it in the scene

Link the camera to have a TPS view

Adapt controls to the keyboard you use. Here are the French settings

Let’s try with another Maze done with Grasshopper

The Grasshopper definition will give a more complex Maze, it’ll a bit more complicated to set up.

Find all sources here : https://www.grasshopper3d.com/forum/topics/maze-from-mesh

We will use the 0.5 version from this page : https://www.grasshopper3d.com/forum/topics/maze-from-mesh but the 0.9 can be also tested.

Let’s open up Grasshopper :

First we design the Surface of the Maze : here it will be a 20×20 square

Then the surface is divided into a grid and the maze is calculated with the script

The output of the script gives the drawing of the Maze

Those lines will be transformed to walls

The result is baked with a Geometry Cache

A material has been created and apply, ready to be exported into Unity

Lescop Maze Grasshopper

Importing in Unity

Extract Textures

Voilà

As it was done before, let’s prepare the Maze for IA.

Let’s add a virus. The covid fits well….

We can now spread the virus randomly. See if it’s possible to reach the End Point without being contaminated.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.