lunes, 15 de agosto de 2016

Generación procedural de circuitos de carreras - Parte 1 | Race Track Procedural Generation - Part 1

Español | English 


Hoy vengo a presentar un nuevo proyecto/desafío. Me propuse crear un algoritmo para crear circuitos de carreras de forma aleatoria en Unity. Esta va a ser la parte 1 de no se cuantas en las que voy a explicar como hago para lograr mi objetivo.

La idea básica sobre la cual va a funcionar el algoritmo es:

  1. Generar un elemento de forma aleatoria
  2. Si ese elemento es una recta, seguir de largo, si es una curva, girar
  3. Repetir 1-2 hasta tener una cierta cantidad de elementos
  4. Buscar la forma de el último elemento con la posición inicial
Hasta ahora estoy en el paso 3. En la cual puedo generar varios elementos y colocarlos como hijos de un elemento llamado "Track". Lo que puedo generar por ahora es esto:


Los elementos rojos son Curvas rectas, los marrones son curvas hacia la izquierda y los violeta curvas hacia la derecha. Por ahora solo quería probar como resultaba el paso 1 y el paso 2.

La lógica (mal hecha) fue: si se crea una recta, mover hacia adelante y generar otro elemento, si es una curva, mover hacia el costado y generar otro elemento y así sucesivamente. 

¿Por qué esta mal? Porque no tomé en cuenta las rotaciones que generan las curvas, para poder apreciarlas voy a necesitar más que una imagen de un cuadrado.

Pero como primera etapa, lo considero adecuado. Lo que tengo que hacer para tener esta etapa bien definida es no solo desplazar la posición antes de generar un nuevo elemento, sino que también rotarlo si el anterior era un curva, para crear un nuevo sentido.

Lo más difícil va a ser la etapa 4, en la cual tengo que hacer que desde la posición final, se creen los elementos necesarios para volver al inicio, algo que se me viene a la mente para hacer esto es utilizar un simple algoritmo de A* path-finding. 

Eso es todo por ahora, espero que les guste el nuevo desafío, cualquier duda o sugerencia pueden dejarla en los comentarios.


-L


-----------------------------------------------------------------------------------------------------------

English


Today I'm here to present a new project/challenge. I made up my mind to create an algorithm that creates race tracks randomly in Unity. This is going to be part 1 of I don't know how many, in which I'll be explaining what I'm thinking in order to achieve my goal.

The basic idea on which the algorithm works is:
  1. Generate a random element
  2. If that element is a straight line, move forward, if it is a curve, turn
  3. Repeat 1-2 until there are a certain amount of elements
  4. Find the way to join the final position with the starting position
For now I'm on step 3. In which I can create several elements and put them as child of a GameObject named "Track". What I can generate by now is this:


The logic (poorly made) was: If a straight line is created, move forward and generate another element, if it is a curve, move to the side and generate another element and so on...

Why it is poorly made? Because I didn't take into consideration the rotations that the curves generate, to be able to see them more clearly I'll have to use something else than a red square.

But for the first stage, I found it right. What I have to do in order to make this stage properly is to not only move the position of the next element that is going to be generated, but also rotate it if the previous element was a curve, in order to create a new direction.

The most difficult stage is going to be stage 4, where I have to figure out a way in which, from the final position, create the necessary elements that are needed to come back to the starting point. Something that comes to my mind for this task might be a simple A* path-finding algorithm.

That's all for now, I hope you like this new challenge, for any doubt or suggestion you can write me a comment.


-L

No hay comentarios.:

Publicar un comentario