Complicated AI is impossible with C2

0 favourites
  • 10 posts
From the Asset Store
A full Spriter-based Platformer engine for C2 or C3
  • 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??

  • 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.

  • 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.

  • 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 :/

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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

  • 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.

    [attachment=0:y3gstqlb]11.jpg[/attachment:y3gstqlb]

  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)