Complicated AI is impossible with C2

Discussion and feedback on Construct 2

Post » Tue Jul 01, 2014 12:56 am

Hello :) i cameto a problem with C2, when it comes to make Complicated AI for a platformer game...its nearly impossible, and while is not 100% impossible, its really overcomplicated and nearly impossible... why??

well, fisrt of all i might be a noob, so if you can disprove my point, please do so.

i manage my AI with instance variables...since is the best option to pick the correct instance...
but when it come to make an action that is triggered by a instance variable...for example to start a Timer once...then its very cumbersome, sinceyou need to changethe instance number or state at the end of the action to make it trigger only once...
for example:

if enemy is overlapping at offset (X: -100) the player
>set enemy variable to 1

if enemy variable = 0
>Move
if enemy variable = 1
>Dont move

if enemy variable = 1
>start timer

On enemy Timer ends
make an attack

(if you pay attention....this wont work...becuaseit will trigger every tick...so you need to do this)

if enemy is overlapping at offset (X: -100) the player
if enemy variable is 0
>set enemy variable to 1

if enemy variable = 0
>Move
if enemy variable = 1
>Dont move

if enemy variable = 1
>start timer
>set enemy variable to 2

On enemy Timer ends
make an attack

is there any other way to trigger once an action when a instance variable changes without having to change the number of the variable at the end???
is it so hard to integrate a trigger once that works for instances??
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Tue Jul 01, 2014 1:04 am

Add trigger once (its under System) to your events. O_o

Seriously.

If Enemy.Var = 1
Trigger Once while True

Do this = Attack

Complex AI is possible. It just requires someone experienced with C2, like anything else really. AI is generally hard.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614

Post » Tue Jul 01, 2014 1:08 am

Trigger once does not work when there are multiple instances. You'll need to add your own trigger variables, or even better, create a state machine.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,679

Post » Tue Jul 01, 2014 1:13 am

@Silverforce like @sqiddster said....trigger once does not work :/ thats my problem

state machine?? i have read about that...i saw a plugin made by some users that creates it, but...why oyu needto use third party plugin?? its cumbersome :/
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Tue Jul 01, 2014 1:39 am

I use For Each Enemy
> Var = X & Trigger Once

It works for the instances that have that variable X.

I also add filtering with Pick Instance by evaluate or comparison in addition to the above.

This way I get my pirate fleet to only chase down a single tradeship instance out of many on the map. In my case, that tradeship is flagged with a variable once its been spotted by the pirates.

I also get a fleet to break up and move off on their own to hunt different targets based on variables as well.

The Pick instance option is really useful for my AI. Anyway, hopefully someone else can help you.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614

Post » Tue Jul 01, 2014 3:16 am

Here's how I do it:

If enemy.mode="wandering"
- wandering code
- if distance(enemy.x, enemy.y, player.x, player.y) is less than 1000, set enemy.mode to "chasing"

If enemy.mode="chasing"
- move toward player
- if distance(enemy.x, enemy.y, player.x, player.y) is less than 100, set mode to "preparing to attack" and set enemy.timervariable to 1

If enemy.mode="preparing to attack"
- subtract dt from enemy.timervariable
- if enemy.timervariable is equal to or less than 0, set enemy.mode and animation to "attacking"

If enemy.mode="attacking"
- on animation finished, set enemy.mode to "wandering"

I also use submodes and/or numbered steps like so:

If enemy.mode="attacking"
- If enemy.mode2="start"
- - if enemy.stepnumber=0

Using this technique it keeps the code isolated and easy to follow while enabling complex behavior, and you don't have to worry about trigger once not working for multiple instances.
Moderator
B
94
S
33
G
33
Posts: 3,006
Reputation: 27,749

Post » Tue Jul 01, 2014 4:10 am

C2 supports a psuedo StateMachine naturally. you can activate and deactivate groups. If you don't need code triggered everytick you can deactivate Groups. And only activate them when the criteria is met. wala state machine.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Tue Jul 01, 2014 5:14 am

@Arima

very interesting :)

but i still think is cumbersome that we needto make counterintuitive coding...when i could be fixed with a "trigger once" that worked for instances...that would fix all, i have zero knowlegde about HTML5 and Java, so i dont know if this have not been added becuase of limitations...in that case im sorry, but if not...then i think this should be adde asap :D
B
23
S
6
G
3
Posts: 316
Reputation: 3,461

Post » Tue Jul 01, 2014 5:31 am

Hi @Lunatrap, @rexrainbow had made a FSM plugin. It is nice to design a state flow chart, and then use this plugin to realize your AI in C2.

http://c2rexplugins.weebly.com/rex_fsm.html

I wrote an tutorial about basic AI design before, but it's not in English.

11.jpg
You do not have the required permissions to view the files attached to this post.
Providence University, lecturer.

Tatung University, lecturer.



Consultant per question: USD$15 / time

Consultant by month: USD$300 / month

Customized project: USD$2500 / capx
B
78
S
16
G
4
Posts: 196
Reputation: 7,688

Post » Tue Jul 01, 2014 1:13 pm

Arima's approach is basically a state machine, and is basically what I would do in this situation. You definitely don't need a third party plugin for that!
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,679


Return to Construct 2 General

Who is online

Users browsing this forum: Artpunk, Sockratease and 8 guests