How do I do an A.I

Get help using Construct 2

Post » Tue Dec 16, 2014 11:58 am

Morning all,

How is possible to make an A.I that jump and/or avoid obstacles automactly?

I need this because i am making a enemy chase my player, but i will only control my player and the enemy needs to avoid obstacles ~by himself~

Any kind of obstacles, like holes in the ground or maybe flying things..
B
9
S
2
G
1
Posts: 92
Reputation: 826

Post » Tue Dec 16, 2014 1:14 pm

simple.

you need FSA (Easiest way to understand it is to check what FSA is and how they work) - state machines.

in short: the easiest state machine is just a state with transition to itself. what does that mean?

state is a abstract thing that describes objects current state (like you for instance) - let's say object is human. you are human right?
and let's say that you have 1 state called sleeping.

so you are object human with state sleep.

that state does nothing byitself. therefore we get transitions - objects that move one active state to another when some condition is met. let's take our human object with state sleep. sleep does nothing byitself
but if we make transition that sleep happens every time after 1 sec passess you get simplest machine. a bit more difficult machine would be if that transition is empty (could and couldn't happen) - describes undetermination - randomness.

but let's take our simple example and move on. now you have a human object who has a state sleep that repeats every 1 sec. now if we add a new state to our human - working - it's just a state. it never happens. but if we add transition from state1 (sleeping) to state2 (working) with condition after 7 hours. our first condition is going to rotate for 7 hours, but once it reaches 7 hours it's gonna go to state2 and stay there. If we then add condition on state2 - 14 hours to go back to sleep - after 14hours of being in state2 it will traverse to state1 back to sleeping. it's shown in the images below.

http://i.imgur.com/QT4O16z.jpg
http://i.imgur.com/hj6f6RN.jpg
http://i.imgur.com/s4gQV8K.jpg

so, what you need really is this - state 1 - running, state 2 - jump high, state 3 - slide / roll /something.
then you need transitions from running state to itself - so it runs indefinitely, and transitions - to state jumphigh if you see /collide/whatever with low object, or to state3 if you colllide/see/is in range /whatever a high object (like flying birds or something). and on both of the state2 and 3 you need to have a transition back to running where it's condition is "after i've avoided"... hard to explain in words, here's the picture down there. what is good about these machines is taht only... your imagination is the limit. you can make 121241241 state machine that will work perfectly. you can make it so big and complex that it's just "like human" if you cover everything you possibly think of.

http://i.imgur.com/xdid0AA.jpg
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Tue Dec 16, 2014 2:51 pm

saiyadjin wrote:simple.

you need FSA (Easiest way to understand it is to check what FSA is and how they work) - state machines.

in short: the easiest state machine is just a state with transition to itself. what does that mean?

state is a abstract thing that describes objects current state (like you for instance) - let's say object is human. you are human right?
and let's say that you have 1 state called sleeping.

so you are object human with state sleep.

that state does nothing byitself. therefore we get transitions - objects that move one active state to another when some condition is met. let's take our human object with state sleep. sleep does nothing byitself
but if we make transition that sleep happens every time after 1 sec passess you get simplest machine. a bit more difficult machine would be if that transition is empty (could and couldn't happen) - describes undetermination - randomness.

but let's take our simple example and move on. now you have a human object who has a state sleep that repeats every 1 sec. now if we add a new state to our human - working - it's just a state. it never happens. but if we add transition from state1 (sleeping) to state2 (working) with condition after 7 hours. our first condition is going to rotate for 7 hours, but once it reaches 7 hours it's gonna go to state2 and stay there. If we then add condition on state2 - 14 hours to go back to sleep - after 14hours of being in state2 it will traverse to state1 back to sleeping. it's shown in the images below.

http://i.imgur.com/QT4O16z.jpg
http://i.imgur.com/hj6f6RN.jpg
http://i.imgur.com/s4gQV8K.jpg

so, what you need really is this - state 1 - running, state 2 - jump high, state 3 - slide / roll /something.
then you need transitions from running state to itself - so it runs indefinitely, and transitions - to state jumphigh if you see /collide/whatever with low object, or to state3 if you colllide/see/is in range /whatever a high object (like flying birds or something). and on both of the state2 and 3 you need to have a transition back to running where it's condition is "after i've avoided"... hard to explain in words, here's the picture down there. what is good about these machines is taht only... your imagination is the limit. you can make 121241241 state machine that will work perfectly. you can make it so big and complex that it's just "like human" if you cover everything you possibly think of.

http://i.imgur.com/xdid0AA.jpg


Very Nice explanation. Even I understood that!

So basically what he said above, you can add conditions (Variables) and if met, do action. so for example if you have a trigger sprite out on the floor in front of the AI and when that trigger overlaps block, then Jump. this is a simple example.
B
8
S
1
Posts: 74
Reputation: 725

Post » Tue Dec 16, 2014 4:02 pm

i would recommend that you use instance variables on your objects. variable numbers/strings/whatever can represent that objects state, and then you can use events like "if human.state == 'sleeping' && timeslept<7h then action sleepmore" (Wheresleepmore adds+1 sec to timeslept) or something like that.
i tell you.. possibilities are infinite.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Tue Dec 16, 2014 4:07 pm

Thank you both!!
B
9
S
2
G
1
Posts: 92
Reputation: 826


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests

cron