Monthly Archives: February 2014

1 Reply

Procedural Maze Generation W/ Pathfinding

I have a weird obsession with procedural generation. Not just levels, but anything. I think it has something to do with my other obsession, math. Either way, I took the procedural maze generation library that I was working on and decided to see if I could get A* pathfinding up and running on it. After hours of complete failure I decided to see what current libraries are out there. I found Simply A*, which was built for the engine I am using. Works perfectly. I did have to do some modification due to not writing this library myself, but so far I’m happy with it. Due to how the path grid is generated, I had to move all of my procedural map generation into the Awake() function so it would fire first, then generate the grid in Start(). For the enemy movement I dumped all “path” objects into an array and pulled a random Vector3 transform from this array every 5 seconds and pushed to the movement script, which is just an extension of the Pathfinding class from Simply A*. If the enemy reaches it’s desired path point before 5 seconds is up, it will randomly pick another so there is constant movement. You can view my proof of concept below. Keep in mind this isn’t a playable game, just a PoC.

http://xertz.net/ProceduralPathfinding/ProcedualPathfinding.html

Enemy movement script:

using UnityEngine;
using System.Collections;

public class SearchPathAI : Pathfinding
{
    public int SearchesPerSecond;
    public float MinDistanceToPlayer = 0f;
    public float AISpeed = 20.0f;
    public float AIPivotPointYValueOverGround = 0.0f;

    private Transform _player;
  public GameObject randomPositionPoint;
  public GameObject[] allPaths;

    void Start()
    {
        GameObject player = GameObject.FindGameObjectWithTag("Player");
    allPaths = GameObject.FindGameObjectsWithTag("Ground");
    InvokeRepeating("RandomPosition", 1, 5);
        if (player != null)
        {
            _player = player.transform;
            StartCoroutine(FindPathTimer());
        }
        else
            Debug.Log("Error: No gameobject found with the tag Player!");
    }

    void FixedUpdate()
    {

        if (Path.Count > 0)
        {
            MoveSearchingAI();
        }
    if(Path.Count <= 0) {
      RandomPosition();
    }
    }

    //A test move function, can easily be replaced
    public void MoveSearchingAI()
    {
        
    if (Vector3.Distance(transform.position, randomPositionPoint.transform.position) > MinDistanceToPlayer)
        {
            transform.position = Vector3.MoveTowards(transform.position, Path[0] + new Vector3(0, AIPivotPointYValueOverGround, 0), Time.deltaTime * AISpeed);
            if (Vector3.Distance(transform.position, Path[0]) < 0.4F)
            {
                Path.RemoveAt(0);
            }
        }
    }

    IEnumerator FindPathTimer()
    {
        //FindPath(transform.position, _player.position);
    FindPath(transform.position, randomPositionPoint.transform.position);
    Debug.Log(randomPositionPoint.transform.position);
        yield return new WaitForSeconds((float)(1.0f / SearchesPerSecond));
        StartCoroutine(FindPathTimer());
    }

  void RandomPosition () {
    int index = Random.Range(0, allPaths.Length);
    randomPositionPoint = allPaths[index];
    StartCoroutine(FindPathTimer());
  }
}

facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a reply

Monday Project – Unity3D 2D Stealth Game

Woke up this morning feeling pretty good. Its nice to be able to sleep in a little bit these days. After some coffee, errands, and a shower I decided to sit down and give a shot at creating a very basic stealth mechanic. I’m not talking Hitman stealth mechanics, I’m talking similar to the grand-daddy of them all, Thief. In thief you play, you guessed it, a thief who has the ability to hide in the shadows and remain unseen. The player is given an on-screen indicator showing how visible they are. This indicator is called the LightGem. When you enter a lit area, your LightGem will change it’s texture based on how lit you are, which in turn helps decide how likely it is for an enemy to see you. There are also other factors such as sound, objects out of place, etc, but I wanted to start small and simple.

I decided that getting a working light detection system was clearly the first thing needed in this proof of concept, considering that is the core of the gameplay of Thief. A few hours after starting I have come up with the following. I use 2DToolKit for the sprite management and NGUI for the UX sprite management. Let me know what you think. I may write a tutorial later on explaining how I did this.

Move with arrow keys or WASD.

http://xertz.net/stealth-game/StealthWebBuild.html

You can view the core code for this project by clicking here.

facebooktwittergoogle_plusredditpinterestlinkedinmail

1 Reply

Weekend Prototype 1

I started working on a new prototype for a platformer on Friday night.  A few days later I have a relatively fully functional 19 level prototype ready for play testing.  Please leave feedback in the comments.

Move Left – A/Left Arrow

Move Right- D/Right Arrow

Jump – Space/Up Arrow

Restart Level – R

http://xertz.net/pixel-jump/pixeljump.html

facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a reply

Dev Blog Time!

Hello and welcome to my space on the web!  I have been making video game prototypes over the last 2 years now and with recently losing my job I’ve decided to start a development blog showing off my projects and documenting my journey through the next year in independent game development.  Feel free to browse around and have a look at my work.

facebooktwittergoogle_plusredditpinterestlinkedinmail