Contribute to the Development of CRYENGINE and Support Indie Developers
Contribute
Forums Gallery LOGIN |REGISTER

Community Archive is read-only - Here you can view content recorded up until February 2017. To join the latest discussions visit our new forums


[C# Video Tutorial] - Creating a 3D maze

Help others by sharing your tutorials here.


 

User avatar crydevJim
Regular Dev
Regular Dev
 
Posts: 419
Member since: 22.06.2013, 21:46
Likes: 262

[C# Video Tutorial] - Creating a 3D maze

Postby crydevJim » 10.04.2016, 06:25

Just a quick tutorial on how to add a 3D maze using C#:

maze.jpg

https://www.youtube.com/watch?v=Cf1FPbAhcPE

Here is the wiki article I mentioned: https://en.wikipedia.org/wiki/Maze_generation_algorithm

And this is the code I used - full credit to the person at Rosetta Code who added the C# example:

Maze generation using DFS: http://rosettacode.org/wiki/Maze_generation#C.23

Changes to SampleApp.cs:

Code: Select all
using CryEngine.EntitySystem;//JB


Code: Select all
         // Create a maze on F6.
         if (e.KeyPressed (EKeyId.eKI_F6)) {//JB
            var maze = new Maze(20, 20);
            for (int i = 0; i < 20; i++) {
               for (int j = 0; j < 20; j++) {
                  myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (i * 9, j * 9, 0), Quat.CreateIdentity (), 3f, "objects/default/mtlbox.cgf");
                  myEntity.Scale = new Vec3 (3, 3, 6);
                  if (maze [i, j].HasFlag (CellState.Top)) {
                     myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (i * 9 + 3, j * 9, 0), Quat.CreateIdentity (), 3f, "objects/default/mtlbox.cgf");
                     myEntity.Scale = new Vec3 (3, 3, 6);
                     myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (i * 9 + 6, j * 9, 0), Quat.CreateIdentity (), 3f, "objects/default/mtlbox.cgf");
                     myEntity.Scale = new Vec3 (3, 3, 6);
                     //myEntity.Position += new Vec3 (4.5f, 0, 0);
                     //myEntity.Scale = new Vec3 (10f, 3f, 3f);
                  }
                  if (maze [i, j].HasFlag (CellState.Left)) {
                     myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (i * 9, j * 9 + 3, 0), Quat.CreateIdentity (), 3f, "objects/default/mtlbox.cgf");
                     myEntity.Scale = new Vec3 (3, 3, 6);
                     myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (i * 9, j * 9 + 6, 0), Quat.CreateIdentity (), 3f, "objects/default/mtlbox.cgf");
                     myEntity.Scale = new Vec3 (3, 3, 6);
                  }
               }
               myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (i * 9, 20 * 9, 0), Quat.CreateIdentity (), 3f, "objects/default/mtlbox.cgf");
               myEntity.Scale = new Vec3 (3, 3, 6);
               myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (i * 9 + 3, 20 * 9, 0), Quat.CreateIdentity (), 3f, "objects/default/mtlbox.cgf");
               myEntity.Scale = new Vec3 (3, 3, 6);
               myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (i * 9 + 6, 20 * 9, 0), Quat.CreateIdentity (), 3f, "objects/default/mtlbox.cgf");
               myEntity.Scale = new Vec3 (3, 3, 6);
            }
            myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (20 * 9, 10 * 9, 0), Quat.CreateIdentity (), 3f, "objects/default/mtlbox.cgf");
            myEntity.Scale = new Vec3 (3, 183, 6);
         //   maze.Display();
         }//JB


I use "mtlbox.cgf". You can copy that over from Crytek\CRYENGINE Launcher\Crytek\CRYENGINE_5.0\Editor\Objects to your project's Assets\objects\default folder.
Hope it helps.

Edit: To get it to work in version 5.1, I had to add <Entity> to the lines with "Instantiate" above. See also the docs for 5.1.
Last edited by crydevJim on 30.07.2016, 09:41, edited 1 time in total.
User avatar seraphire
Just getting started
Just getting started
 
Posts: 1
Member since: 20.04.2016, 07:31
Likes: 0

Re: [C# Video Tutorial] - Creating a 3D maze

Postby seraphire » 24.04.2016, 05:50

Great tutorial Jim! I'm brand new to CryEngine and this got me started with Mono. Thank you! :)

I noticed a couple of code elements that you added to the code in the YouTube video but missed in your write up. These are at the top of the code as module level variables. I had to change my position values because my view window started me at a different location than yours.

Code: Select all
      private EntitySystem.Entity myEntity;
      private Vec3 position = new Vec3(40, 40, 40); //JB

Additionally, I had to copy the mtlbox.mtl file as well to get the surface for the box.

In case this might help someone else:

The sample SampleApp.csproj that I copied over from the CryEngine directory had me start the game engine instead of the sandbox. I discovered if I modify the Code\CESharp\MonoLauncher\MonoLauncher.csproj near the bottom of the file (it's xml) There is a key:

Project/ProjectExtensions/MonoDevelop/Properties/CryEngineParameters

If I change this from GameSDK to Sandbox it opened in the Sandbox as you do in the video.

Thank you for all the information in an awesome tutorial!
User avatar goloox
Just getting started
Just getting started
 
Posts: 1
Member since: 16.04.2012, 16:51
Likes: 0

Re: [C# Video Tutorial] - Creating a 3D maze

Postby goloox » 26.07.2017, 14:29

HI,could you make new tutorial for 5.3 because myEntity = EntitySystem.Entity.Instantiate <Entity>(position + new Vec3 (i * 9, j * 9, 0), doesn't work anymore



Time : 0.119s | 22 Queries | GZIP : Off