How do I set and play attack animations on landscape games

Get help using Construct 2

Post » Fri May 30, 2014 10:20 am

I am glad that you made it work!

Now, I haven't really done any search for enemy AI yet, didn't need to. I am not sure about the 4 directions and the path finding though. The only true benefit by using it will be if you have obstacles. Otherwise, using events you will probably have more control around the enemy's movement.

This is a capx I had made for an other topic, the goal was for the enemy to move vertically until he line him self up with the player and then move towards him, in a Double Dragon fashion. You can get some info out of it that might help you build your own movement.

DoubleDragon.capx


As for the attack, just make a distance comparison* (or use an invisible sprite that is bigger than the enemy's sprite and check for overlap) and when true, set an Instance variable "Attack" to true and create the necessary events for the enemy's attack.

*The distance comparison should look like this:

(System - Compare 2 values)
distance(Player.X, Player.Y, Enemy.X, Enemy.Y) < any number you want ----> Player set Boolean "Attack" to true
distance(Player.X, Player.Y, Enemy.X, Enemy.Y) > the same number as above ----> Player set Boolean "Attack" to false
You do not have the required permissions to view the files attached to this post.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Sun Jun 01, 2014 12:21 am

I'm actually using Pathfinding at the moment since there are obstacles in the map. What I can't figure out is how to make the enemy play the right animations while walking in a specific direction. Right now, they can find the player quite easily, but they don't actually use any of the animations I set for them. I reckon I should do something similar to what I did with the character's movement animations (Setting the direction, then playing an animation depending on which one is active). I disabled diagonals and "rotate object" to avoid problems, and I think I have an idea on how to make the enemy attack when it's next to the character, but I would appreciate any help on how to make the enemy walk in the right direction while moving.

PS: Using "Find path to (Character.X, Character.Y)" the enemies go straight for my location, but they never move from there afterwards. Any idea on how to update my location?

Update: The enemies are dealing damage while playing their animations now.
B
4
Posts: 17
Reputation: 234

Post » Sun Jun 01, 2014 2:11 am

I understand. I' ve updated and attached the example. It's not perfect, I don't know how to calculate the angles in a predictable manner. Some times, C2 returns a 180 degree value and other times it returns -180 degrees, which in essence are facing at the same same way, but brake down the conditions which set the direction variable... I am sure there is a mathematical formula that fixes that, but I am unaware of it. For the time being, try to improve upon this, until some wise forum member comes to the rescue! :lol:
You do not have the required permissions to view the files attached to this post.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Sun Jun 01, 2014 3:12 pm

Ok, I think I fixed it. Check it out below. On a side note, perhaps gameplay wise it would be better to use the angle(enemy.X, enemy.y, player.X, player.Y) to determine the attacking direction/animation, since there are moments that the enemy moves toward the player but the direction he is moving doesn't match the direction he should be facing/attacking.
You do not have the required permissions to view the files attached to this post.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Sun Jun 01, 2014 10:54 pm

Do you known if it could be possible to swap out the current global "ang" variable for a normal instance variable? assuming there's more than one enemy on screen, wouldn't this make all of them play the same animation regardless of where they are?
B
4
Posts: 17
Reputation: 234

Post » Sun Jun 01, 2014 11:25 pm

Yes it would and yes you should make it an Instance variable. You might need to add a "for each" condition in order to work however. I am not familiar with the path finding AI but you can check this topic viewtopic.php?f=147&t=103574 to see how @jcook handled the multiple enemies logic in his capx. :)
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Mon Jun 02, 2014 12:45 pm

I got the enemies to move and attack! Everything's working out great so far. My only problem at the moment is that they only attack when all of them are in range (they're melee, so unless they're all around you, they won't attack). One of the enemies seems to be able to attack me while being alone, and he deals more damage than the rest, so the melee attack system is kinda flawed. Any idea on how to make the system calculate distance individually? Here's a screencap of the events being used.
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 17
Reputation: 234

Post » Mon Jun 02, 2014 3:21 pm

Add a "for each enemy" into your condition (put it above the distance check) and see if that fixes it.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

Post » Mon Jun 02, 2014 10:00 pm

It didn't fix it, unfortnately. However, since they're melee, I just replaced the distance event with "On collision with (player)", so it's working now. Thanks a lot for the help!
B
4
Posts: 17
Reputation: 234

Post » Mon Jun 02, 2014 11:51 pm

I am glad that you made it ;)

Keep it up!
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: uzumiapps and 26 guests