2D VideoGame Development - FactoryRun: Animation & Artificial Intelligence. (Enemy) / Inteligencia Artificial & Animaciones (Enemigo). Part.2 [ESP/ENG]

in Hive Gaming3 years ago

bg.gif

Hola a todos!

Seguimos con el desarrollo de lo que hasta ahora es un mini juego porque planeo agregar al menos 4 modos de juegos, entre ellos el multijugador online. Si aún no has visto mi post anterior te invito a verlo para que veas el progreso, y además entiendas parte de lo que explicaré en esta publicación.

We continue with the development of what until now is a mini game because I plan to add at least 4 game modes, including online multiplayer. If you have not yet seen my previous post, I invite you to see it so you can see the progress, and also understand part of what I will explain in this publication.

En este post configuraremos brevemente las animaciones del enemigo y explicaré que necesitas para establecer la inteligencia artificial, y de esta forma preparar el siguiente modo de juego en el cual trata de Supervivencia o por Oleaje. Aún no tengo muy claro de como será el diseño del nivel pero se me ocurrirá algo mientras avanzo. De todas formas puedes dejar tu idea en los comentarios.

In this post we will briefly configure the enemy animations and I will explain what you need to set the artificial intelligence, and in this way prepare the next game mode in which it deals with Survival or Wave. I'm still not very clear on what the level design will be like but something will occur to me as I go along. Anyway you can leave your idea in the comments.

Animacion del enemigo / Enemy animation

Ya hemos animado al personaje principal, ahora tenemos que animar al enemigo para ello usaremos las siguientes animaciones. Si quieres aprender en detalle como animar un personaje en Construct 3 visita el post anterior.

We have already animated the main character, now we have to animate the enemy for this we will use the following animations. If you want to learn in detail how to animate a character in Construct 3 visit the previous post.

Idle: Es la animacion cuando el enemigo está en reposo o detenido.

Idle: It is the animation when the enemy is resting or stopped.

Idle.png

Walk: Usaremos esta animacion para cuando el enemigo se desplace por el nivel.

Walk: We will use this animation for when the enemy walks through the level.

Walk.png

Ataque: Con esta animacion el enemigo podrá herir o dañar a nuestro personaje principal.

Attack: With this animation the enemy can hurt or damage our main character.

Attack.png

Muerte: Cuando la salud del enemigo llegue a 0, esta animacion se activará.

Death: When the enemy's health reaches 0, this animation will activate.

Death.png

Hurt: Usaremos esta animación para cuando el enemigo reciba un golpe.

Hurt: We'll use this animation for when the enemy gets hit.

Hurt.png

Puedes descargar el kit de animaciones en el siguiente enlace:

You can download the animation kit at the following link:

https://craftpix.net/freebies/free-city-enemies-pixel-art-sprite-sheets/

Previsualización de las animaciones / Preview of the animations

animationenemy.gif

Inteligencia artificial (AI)

En los siguientes eventos crearé la inteligencia artificial para que cuando el enemigo vea a nuestro personaje lo persiga hasta atacarlo. Para esto primero debemos establecer tres comportamientos:

In the following events I will create the artificial intelligence so that when the enemy sees our character, he will chase him until he attacks him. For this we must first establish three behaviors:

Comportamientos / Behaviors

  • Solido: Este comportamiento se encarga de que nuestro enemigo pueda interactuar o chocar de alguna forma con otro solido.
  • Linea de Vision: Este es el comportamiento más importante para crear la inteligencia artifial. Este se encarga de establecer un rango invisible para detectar un objeto o posiciones.
  • Plataforma: El comportamiento plataforma se usa para los controles de los personajes. Al igual que el personaje principal tambien debemos aplicar este comportamiento al enemigo y de esta forma pueda moverse.

- Solid: This behavior ensures that our enemy can interact or collide in some way with another solid.
- Line of Sight: This is the most important behavior to create the artificial intelligence. This is responsible for establishing an invisible range to detect an object or positions.
- Platform: The platform behavior is used for character controls. Like the main character we must also apply this behavior to the enemy and in this way he can move.

image.png

Hoja de eventos / Event sheet

Una vez establecidos los comportamientos ahora debemos programar las animaciones y la inteligencia artificial para darle vida al enemigo. Estas instrucciones las prograraremos en la misma hoja de eventos donde establecimos las del personaje principal.

Once the behaviors have been established, we must now program the animations and artificial intelligence to bring the enemy to life. We will program these instructions in the same event sheet where we established those of the main character.

Inteligencia artificial (AI):
Primero creamos un evento en el cual llamamos a la linea de vision del enemigo.

  • Si el personaje está en la linea de vision del enemigo, (como referencia el punto de imagen 0). Entonces...
  • Decimos que si la posicion X del enemigo es menor que la posicion en X del personaje. Este ejecutará las animaciones de movimiento hacia a la derecha.
  • En cambio, si la posicion X del enemigo es mayor que la posicion en X del personaje, éste irá hacia a la izquierda.
  • Tambien establecemos que si la distancia del personaje al enemigo es igual o menor que 80px. El enemigo reproducirá la animación de ataque.

First we create an event in which we call the enemy's line of sight.
- If the character is in the line of sight of the enemy, (as reference the image point 0). Then..
- We say that if the position X of the enemy is less than the position in X of the character. This will run the motion animations to the right.
- On the other hand, if the enemy's X position is greater than the character's X position, the character will go to the left.
- We also establish that if the distance of the character to the enemy is equal to or less than 80px. The enemy will play the attack animation.

image.png

Tambien configuramos otros eventos de inteligencia para el enemigo.

We also set up other intelligence events for the enemy.

  • Cuando el personaje choque con una pared a su izquierda, este simulará un salto.
  • Cuando el personaje choque con una pared a su derecha, este simulará un salto.

- When the character hits a wall to his left, he will simulate a jump.
- When the character hits a wall to his right, he will simulate a jump.

De esta manera creamos una intelegencia artificial más completa. Aunque no hayamos configurado una animacion de salto al enemigo, el sistema puede simular esto. Además, tambien establecemos que si el enemigo se detiene, se activará la animacion de reposo (idle).

In this way we create a more complete artificial intelligence. Even though we haven't set an enemy jump animation, the system can simulate this. In addition, we also set that if the enemy stops, the idle animation will be activated.

image.png

Animation Test

Este es el resultado de las configuraciones antes realizadas:

This is the result of the configurations made before:

enemies3.gif

Podemos ver que ahora el enemigo tiene vida propia en el juego y puede realizar diferentes acciones por si solo. Esto ha sido todo por este tutorial, en el siguiente post trabajaremos en la barra de vida de los personajes y algunas configuraciones, como el spawn de los enemigos en el nivel.

We can see that now the enemy has its own life in the game and can perform different actions on its own. This has been all for this tutorial, in the next post we will work on the life bar of the characters and some configurations, such as the spawn of the enemies in the level.


Para disfrutar la primera version del juego puedes ingresar al siguiente link:
To enjoy the first version of the game you can enter the following link:

Play Factory Run


Kind regards!
Oscar

cover_perfil.png
Todas las imagenes o captures son de mi propiedad.

Sort:  

I tried it a couple of time and the game is running nice! Only issue I had was that sometimes the platforms were to high for the jump so it was impossible to get up there. Not sure if I maybe missed something.

Have you tried double jumping? You can also go to the right when you are in the air, to boost. Thank you for having tried the game, greetings friend.

Congratulations @oscarcc89! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You received more than 25000 upvotes.
Your next target is to reach 30000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Support the HiveBuzz project. Vote for our proposal!