Some basic AI trouble (now w/ a capx)

Get help using Construct 2

Post » Thu Oct 03, 2013 2:26 am

Hey guys,

I'm trying to make a game with some simple AI behavior for the Magical Girl Jam. But I'm running into two big problems.

Firstly, I have an NPC sprite that I'm trying to give some basic AI to. The NPC should move a bit left or right and then pause before moving again. The NPC has four instance variables:

FSMState (integer; tracks what state the NPC AI is in)
PauseTime (integer; how many more ticks the NPC should stay still for)
MoveDirection (integer; -1 if the NPC hasn't decided on a direction to go yet, 1 if the NPC is going left and 0 if the NPC is going right)
MoveDistance (integer; how many more ticks the NPC should move for)

When I start up the Store layout, the NPC does not move and just faces right. My event logic for controlling her is in GeneralEvents. If I use debugger mode I can see the variables changing properly, but she never moves.

Am I doing something wrong? Is there a better supported way to be doing AI stuff? Is this a bug? I don't know! Please tell me.

My second problem with this project can be best seen in the Test Layout. In it, I have two sprites that have been given the Platforming behavior. One sprite uses my NPC's graphic and the other sprite uses my monster graphic. Below them is a jump through platform sprite. When you start the layout, the two sprites fall towards the platform and then stop on it. However, the monster sprite stops lower than the NPC sprite. This happens no matter what browser I use or what their origins are. The TestGirl and TestMonster objects are exactly the same except for their graphics, so I'm not sure why they're doing this? Perhaps this is a bug?

Here is a link to a .capx that demonstrates both these problems:

I'm using r146 64-bit version from Steam if that makes a difference.

Thank you in advance for advice.

Edit: Oh. Looks like half my post got eaten when I tried to post initially. Welp... I've fixed it now.JumbocactuarX272013-10-03 04:07:18
Posts: 8
Reputation: 216

Post » Thu Oct 03, 2013 3:39 pm

For the first problem you need to set MoveDirection to floor(random(2)) to get a 0 or 1. random(2) will give you numbers like 0.695915905746739 which you can see in the debugger.

For the second you need to fix the sprite collision polygons. That's the area that collides with solids.

Posts: 1,520
Reputation: 25,650

Post » Thu Oct 03, 2013 5:30 pm

Ah! I can't believe I didn't realize that first one. I'll be sure to put in a floor function later. Thank you for pointing this out.

For the second, I didn't even know that there were sprite collision polygons! Thank you very very much for informing me of this!
Posts: 8
Reputation: 216

Return to How do I....?

Who is online

Users browsing this forum: Armench and 16 guests