Monster AI

Get help using Construct 2

Post » Tue Jul 24, 2012 11:42 pm

I want the Monster AI to move using the 8Direction Control just as the player is, but i want the monster to only start to walk towards player when in certain distance (playing movement animations face the correct direction, same as player).

Any ideas? Basically i want the monster to walk towards player and then start to attack.

Anyways here my .capx of the player movements , if anyone could clone the player and make that use the monster AI then i can add my monster animations in when i suss out how to actualy use Monster AI



Download Capx
B
4
Posts: 33
Reputation: 391

Post » Wed Jul 25, 2012 12:52 am

Are you aware of the distance() expression? That could help significantly.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Jul 25, 2012 7:59 am

No i wasn't , how do i simulate 8direction control on something similar to my player animations? for now i just want to clone my player and make a version that attacks the current player using Monster AI ... but i have no idea on how to simulat control towards player

I guess having Free edition won't help me since i cant check directions like "N" or "NE" .....
B
4
Posts: 33
Reputation: 391

Post » Wed Jul 25, 2012 2:15 pm

When saving your project, select "Save as single file" to get a .capx. You have attached a .zip file of your project files.

The .capx is basically just an archive of your project (like .zip), but we can open it directly in C2 without having to extract the archive and cluttering our folders with a bunch of project files.

Now, on to the question:
The easiest way is if you use the bullet behaviour on your enemies, and when your character is within a certain distance (use the distance expression like squiddster said), rotate your enemy towards your player. (use the action "Rotate towards position")

Now, you have 8 animations for the enemy? You can compare the angle of the object to see which direction it's moving. If the angle is within 45 degrees of the angle 0 for example, the enemy is moving right. If within 45 degrees of the angle 45 degrees it's moving down-right, if within 45 degrees of the angle 90 degrees, moving down, etc..

Edit: And btw, the free edition only limits the amount of events and the amount of layers in each layout. All the features are available except for families.Nimtrix2012-07-25 14:16:39
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Jul 25, 2012 3:41 pm

Okay...i got it lol, Thanks guys.

Any examples of getting the monster to attack when it reaches player ? ofcourse the distance would be needed to stop the monster from moving into player constantly. lodose2012-07-25 15:48:43
B
4
Posts: 33
Reputation: 391

Post » Wed Jul 25, 2012 3:52 pm

Oh I see, it's just my standard response to a zip upload. We get a few of those. The .capx is a renamed .zip file, but I've seen them not open correctly on some hosts before, so I know what you mean. Most of us use dropbox so we don't have that problem.

I think classic is pretty much the same, but I can't really answer that, never used it.

If you use the bullet behaviour, the object will move forward along it's angle. Then you just set the angle by using the action "Set angle towards position 'Player.X, Player.Y'".


Edit: Well, I guess you edited your post before I replied, so if anyone's wondering, that's why my post is totally unrelated to the above.

To make him stop, just use the distance expression again, if he's close enough, he stops moving and attacks instead.Nimtrix2012-07-25 16:01:28
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Jul 25, 2012 4:08 pm

I cant seem to get the animation right without it being upside down and if i disable it from rotating it moves in only one direction ... confusing :(

If you check out my capx ... you can see the style of my game , i need things to run smoothly on the diagonals and not strife ... so in terms using snap to grid path finding. The bullet movement is too fluent to control with the animations i have lodose2012-07-25 16:13:15
B
4
Posts: 33
Reputation: 391

Post » Wed Jul 25, 2012 4:14 pm

Hmkay, check your bullet behaviour's properties (select object, then in the panel to the left) and set "Set angle" to "No". Then, instead of setting the angle of the sprites in the event sheet, use "Set bullet angle of motion". Input "angle(Enemy.X, Enemy.Y, Player.X, Player.Y)" as the parameter when prompted.

Edit: Ok, never mind the above then.Nimtrix2012-07-25 16:15:16
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Jul 25, 2012 4:20 pm

Actually mate, it seems that method works a charm , guessing i need to check angle to play animations ??

Thanks for your help again mate :)
B
4
Posts: 33
Reputation: 391

Post » Wed Jul 25, 2012 4:25 pm

Yeah, but you can't compare the sprite's angle like I said above, since that will always be to the right. (since we no longer change it)

You need to use "System: Is between values" and compare 'Enemy.Bullet.AngleOfMotion'.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Next

Return to How do I....?

Who is online

Users browsing this forum: ManuelPerez and 25 guests