lunes, 10 de julio de 2017

Rock Climber - Part 9

Español | English



Nuevo progreso! En los momentos libres que tuve me dediqué a seguir con la generación procedural de las montañas, lo último que me faltaba era cómo hacer que se muestren en pantalla ya que hasta ahora solo había una línea que delimitaba su forma.

Por lo que tuve que aprender lo básico de como funcionan las Mesh en Unity y como se muestra una imagen, como a partir de puntos se crean triángulos y a partir de unos cálculos estos van a ser las imágenes que vemos. Por supuesto que esto lo tuve que hacer a mano porque debía crear la imagen a partir del contorno que había hecho.

Entonces el proceso fue el siguiente: Crear a partir de los vértices de la montaña nuevos vértices, con estos luego iba a formar triángulos y después simplemente pasar toda esa información a un objeto Mesh de Unity y este se iba a encargar de hacer el resto. Por suerte no tuve que meterme con muchas cuentas o cálculos de vectores normales por la iluminación ya que el juego es 2D, lo que hace que haya una sola fuente de iluminación y por lo tanto que sea la misma en todas.

Entonces utilicé el siguiente método:


Los puntos que creé que menciono más arriba son los puntos de la izquierda, los impares. Estos iban a estar a la misma altura que los puntos de la montaña pero en un valor de x fijo.

Lo más importante a tomar en cuenta es como se construye el camino naranja (el camino Hamiltoneano en un grafo bipartito). Lo que decidí hacer es ir intercalando vértice a vértice según la numeración, eso trae la ventaja de que forma los triángulos que podemos ver resaltados.

Unity para crear un Mesh necesita 2 arrays (como mínimo), uno de Vertices y otro de Triángulos. El de vértices es simplemente pasarle todos los vértices de la montaña más los que se crearon sobre el eje azul. El vector de triángulos es un vector en el cual en cada posición se le asigna un índice, este índice corresponde al vértice. Entonces por ejemplo triángulo más abajo esta dado por los vértices 0, 1 y 2. Los mencioné de esa manera ya que al ordenar los vértices, se debe hacer en sentido horario.

Haciendo sobre toda la montaña, se pueden tener resultados como el siguiente:


Por lo cual estoy bastante satisfecho con el resultado. Lo siguiente es buscar la forma en la cual pueda agregar los obstáculos en los lugares más adecuados.

Hasta pronto.

-L

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

English



New progress! In the moments when I had some spare time I continue working on the procedural generation of the mountains, the last thing I was missing was making them be shown in the screen as until now, the only thing that could be seen was their shape.

So I had to learn the basics of how Meshes work in Unity and how an image is displayed, how from a set of points triangles are created and then, based on them, the triangles are created and after some calculations, an image as we know it is shown. Of course I had to sort of do it from scratch as I was trying to make an image out of the border of the mountains.

So I followed the next process; First create a new set of Vertex based on the vertexs of the moutain's border which with all theese I would later on create the triangles and finally pass all that information to Unity to let it handle the rest. Luckily I didn't have to mess around too much with calculations of normal vectors for the illumination because it is a 2D game, so there is only one source of light and every object has the same one.

So I made the following method:


The poins I created which I mention earlier are the ones on the left, the ones with odd numbers. This will be at the same height than each point of the border of the mountain but they will have a fixed x position.

The most important thing to notice is how the orange path is built (The Hamiltonian path in a bipartite graph). What I decided to do was to switch from one vertex to another following the enumaration, this brings the huge advantage of forming the triangles we can se highlighted.

Unity needs 2 arrays (minimum) for creating a Mesh, one of Vertex an another of Triangles. The one of the Vertex was simply pass all the vertexs of the montain's border and then give the new ones I've created along the blue axis. The Triangles vector is a vector in which in every position, an index is assigned, this index corresponds to a vertex. So for example, the lowest triangle is given by the vertexs 0,1 and 2. I mentioned them in that order because when ordering vertexs, it must be done in a clock-wise orientation.

By doing this all over the mountain, the following result could be obtain: 




So I'm quite satisfied with the result. The next thing is to find a way in which I can place the obstacles in suitable places.

See you soon.

-L

1 comentario:

  1. Tiene conocimientos en Python? En cuya caso, tengo interes en desarrollar un programa con usted.

    ResponderBorrar