viernes, 4 de marzo de 2016

Nerdy Run Día 6 - Primer mini-juego creado | Nerdy Run Day 6 - First Mini-game created

Español | English


Ya creé el primer mini-juego! Es el primero de 4 y estimo que el más difícil de crear de todos. Ya pude resolver los problemas de los cuales hablé en la entrada anterior que básicamente era sobre la lectura de los ángulos Euler.

Estos ángulos no son exactos, si uno hace un Debug.log de los valores se va a dar cuenta que dan valores como 90.00001 o 270.001 en vez de ser exactos, por lo que esto conlleva a que no se pueden utilizar para leer datos. Esto hacía que si yo esperaba que una acción ocurra si el ángulo era 90° no lo iba  reconocer, ni siquiera cuando utilizaba los ángulos como el 90.0001 que era lo que aparecía.

Por eso, los ángulos Euler son para escritura solamente, nos pueden ayudar mucho para un objeto según un determinado vector pero no para leer los ángulos que nos da ni tampoco para utilizarlos en estructuras IF.

Por lo que tuve que inventar un método para indicar en que posición se encontraba cada botón, si miraba para arriba o para abajo, etc. Para esto recordé el sistema de cuadrantes en matemática, desde 0° a 90° los ángulos están en el primer cuadrante, dentro de 90° a 180° en el segundo, etc. Por lo que lo que hice entonces es asignar, dependiendo a que ángulo este rotado el botón, a que cuadrante corresponde, y desde ahí si pude utilizar el número de cuadrante como parámetro para el juego.

Luego de eso tuve que crear la rotación inicial, una rotación aleatoria. Para esto, en la función Start() utilicé un truco que utilizaba en matemática para otro tema pero que también servía:

GetComponent<RectTransform>().Rotate(new Vector3(0, 0, (90 * Random.Range(1, 5))));
Lo que hace eso es agarrar el RectTransform (que es el Transform de cada botón) y rotarlo 90° X veces, ese valor X es un valor cualquiera entre 1 y 4. Por último, solo queda des-habilitar todo el mini-juego para que se active cuando el jugador se encuentre con uno de los profesores...

-L

--------------------------------------------------------------------------
English


I created the first mini-game! This is the first of 4 and I think it is the hardest to create. I could solve the problems which I've mentioned on the last entry which where basically about the readings of the Euler angles.

This angles aren't exact, if one does a Debug.log of the values he/she will realize that they are values like 90.0001 ir 270.001 instead of being exact, which leads to not being able to read this data. This caused that if I wanted to run an action depending on the value of 90° it wouldn't recognize it, not even if I used the same value that it gave me, like 90.0001.

That is why, Euler angles  are write-only, they can be really useful to rotate an object depending a given vector but not to read the angles and neither to use them on IF structures.

So I had to figure a way that would indicate the position of the rotation of each button, if it was looking up or down, etc. For this I remembered the Quadrant system in Mathematics, angles between 0° and 90° belongs to the first Quadrant, angles between 90° and 180° belong to the second Quadrant and so on. So what I did was to assign, depending at which angle the button was rotated, the corresponding Quadrant and from there I can use the Quadrant number as a parameter of the game.

Then, I had to create the initial rotation, a random rotation. For this, on the Start() function I used a trick that I used to use on math for another topic but it also works:

GetComponent<RectTransform>().Rotate(new Vector3(0, 0, (90 * Random.Range(1, 5))));
What this does is to grab the RectTransform (each button's Transform) and rotate it 90° X times, where X is a random value between 1 and 4. Finally, all that remained was to un-able the mini-game so it actives itselft when the player meets one of the proffesors...

-L

No hay comentarios.:

Publicar un comentario