How do I make AI that runs away from the player?

Get help using Construct 2

Post » Tue Dec 22, 2015 3:34 pm

I'm currently making a survival simulation game, and I need help desperately with the AI. I made a thread about this a while ago but I don't think I explained it well enough. I already have a system for the prey to detect the predator (you), but getting the prey to actually run away from the player is a problem. I've uses a method of changing it's angle once it is supposed to run away from me every tick to 180% towards the player and in this same tick -180 degrees away from the player. I also use bullet movement. The ultimate problem I'm having though is that I have no idea how to make it turn away from objects on the layout. Say there is a tree in the way, what do I use for it to detect the tree individually as a single instance, and have it turn away from said object. Walls are also a big problem, as once it turns, say, 90%, it will still be facing the wall or running along it, causing it to glitch. When the prey turns away however, using the system I use (line of sights detection 'collision boxes' and increasing angle clockwise by 90%), It is also at the same time turning away from the player which causes it to not really turn at all and just spaz through entire walls or mountains.

So, any suggestions on how to make an object 'run away' from the player and detect walls / other objects infront of it, therefore turning it away? :oops:
B
26
S
10
G
4
Posts: 77
Reputation: 4,171

Post » Tue Dec 22, 2015 3:36 pm

Would using pathfinding work for you?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Dec 22, 2015 3:38 pm

LittleStain wrote:Would using pathfinding work for you?


Not really, as there is no point that I want to direct it to. It's an open world game, and I need it to run away naturally and react accordingly with it's surroundings. No way to pathfind away from an object unfortunately without setting a predetermined point.
B
26
S
10
G
4
Posts: 77
Reputation: 4,171

Post » Tue Dec 22, 2015 3:42 pm

Yeah.. so you could set a point 500px away from the player at a certain angle, right?

Wen it's far enough away from the player your prey could go back to idle, or not?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Dec 22, 2015 3:50 pm

LittleStain wrote:Yeah.. so you could set a point 500px away from the player at a certain angle, right?

Wen it's far enough away from the player your prey could go back to idle, or not?


It would probably get it's destination stuck inside an object though, or it would double back and run straight towards you if your in an enclosed areas such as a valley, and the destination is just outside the valley, causing it to just run straight into you to get out of the valley. I guess It could work though, not sure how I would do it?
B
26
S
10
G
4
Posts: 77
Reputation: 4,171

Post » Tue Dec 22, 2015 4:37 pm

PrimalNews wrote:
LittleStain wrote:Yeah.. so you could set a point 500px away from the player at a certain angle, right?

Wen it's far enough away from the player your prey could go back to idle, or not?


It would probably get it's destination stuck inside an object though, or it would double back and run straight towards you if your in an enclosed areas such as a valley, and the destination is just outside the valley, causing it to just run straight into you to get out of the valley. I guess It could work though, not sure how I would do it?


Basic example

Now you will have to find a way to move the destination, when it's either overlapping or outside the layout..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Dec 22, 2015 4:48 pm

LittleStain wrote:
PrimalNews wrote:
LittleStain wrote:Yeah.. so you could set a point 500px away from the player at a certain angle, right?

Wen it's far enough away from the player your prey could go back to idle, or not?


It would probably get it's destination stuck inside an object though, or it would double back and run straight towards you if your in an enclosed areas such as a valley, and the destination is just outside the valley, causing it to just run straight into you to get out of the valley. I guess It could work though, not sure how I would do it?


Basic example

Now you will have to find a way to move the destination, when it's either overlapping or outside the layout..


Unfortunately that cap.x is in verion 219, I don't really want to use a beta version as It might mess up my game... :/
B
26
S
10
G
4
Posts: 77
Reputation: 4,171

Post » Tue Dec 22, 2015 4:54 pm

I'm not sure which part of your game you are worried about, but that's your choice..
The next stable release will probably be somewhere in january..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Dec 22, 2015 5:32 pm

Well I tried it out, and It's really frustrating to try and understand. Do you have any other method? This creates lots of problems. 1. The destination object isn't binded to any 'prey' so multiple prey will run towards a single one is no others are nearby or something. I don't know, It all doesn't make sense to me, It's giving me a headache. How were multiple objects created to be put ontop of the prey items when there was no event stating to spawn one for each instance of prey and there was only one at the start of the layout. Also, if I were to implement wandering AI, the destination wouldn't change with it and therefore wouldn't be able to run away since It wouldn't be ontop of the destination. Any explanation or other way to do it? I hate the idea of using an object for it to pathfind to because of all these problems. >.<

I think I'm going to have a migrane from this stupid AI that I'm trying to make.
B
26
S
10
G
4
Posts: 77
Reputation: 4,171

Post » Tue Dec 22, 2015 5:47 pm

PrimalNews wrote:Well I tried it out, and It's really frustrating to try and understand. Do you have any other method? This creates lots of problems. 1. The destination object isn't binded to any 'prey' so multiple prey will run towards a single one is no others are nearby or something. I don't know, It all doesn't make sense to me, It's giving me a headache. How were multiple objects created to be put ontop of the prey items when there was no event stating to spawn one for each instance of prey and there was only one at the start of the layout. Also, if I were to implement wandering AI, the destination wouldn't change with it and therefore wouldn't be able to run away since It wouldn't be ontop of the destination. Any explanation or other way to do it? I hate the idea of using an object for it to pathfind to because of all these problems. >.<

I think I'm going to have a migrane from this stupid AI that I'm trying to make.


The destination object is binded to a specific prey, as it's in a container with it..
If you want the prey to wander inbetween, just pin the object to the prey and unpin it when having to run away..
You could also use the pin to rotate the prey to prevent overlapping of the destination..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: Congrats2u, FTGamingco, theinfomaven and 11 guests