TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 28 Dec 2011 11:14 PM |
Well, for awhile now i've been thinking of a way to make an ai, and well i've found one thats actually pretty simple.
It'll have its current position, the position it needs to get to, and a table. Those are the 3 vital things it will need.
Lets pretend this table is called "Moves". You see, the ai will only move Forward, Backward, Left and Right. Nothing more. It'll function like this;
It will raycast to see if it can get to the objective, and if it can it will just walk directly there. If it can't, because something is blocking the way, it raycast directly in front of it to see if it can move forward. If there is atleast a distance of X studs range, it will walk about 3/4th of the way there, stop and repeat. If it can't move forward, it will try to move to the left. If it can't move to the left, it will move backwards, if it cant move backwards, it will move to the right.
One important note, is that, for example if the AI moves forward in one move, the string "Up" is added to the table 'Moves'. The AI will then try to move in a direction again, by trying to raycast, then if something blocks the way, will try to move Forward again, Left or Right. It won't move backwards until it can not move in any direction. In the case it can't, "Moves" is cleared, and the AI once again trys to move.
I hope I explained this idea well, I think I actually over explained it.. ^.^? By the way, if this is actually an existing method, please tell me :D? |
|
|
| Report Abuse |
|
|
TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 28 Dec 2011 11:18 PM |
For the "It cant move backwards" section, I think I left it rather vague. If the AI moved Up, it wont be able to move Backwards. If it moved Backwards, it won't move back Up. If it moved to the left, it wont move back to the right.
The only way this rule is bypassed, is if there are no other possible routes. |
|
|
| Report Abuse |
|
|
b3njam1n
|
  |
| Joined: 05 Nov 2007 |
| Total Posts: 19389 |
|
| |
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 28 Dec 2011 11:24 PM |
| b3n found this really interesting |
|
|
| Report Abuse |
|
|
TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 28 Dec 2011 11:25 PM |
It would be nice to see this plan in action. ^.^ Although, I've already noticed one problem with this. If the objective is placed in an area, surrounded by walls, and the doorway is in the middle of the walls, the ai will run in an endless loop trying to get indoors, and eventually will figure it out. The AI is really only effiecent with dead ends, and where there aren't pathways just in the middle of anything. It has to be either at the start, or the end of the wall (the door.) |
|
|
| Report Abuse |
|
|
| |
|
| |
|
NVI
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 4744 |
|
|
| 29 Dec 2011 12:08 AM |
| i found this interesting but i didn't read it at all |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2011 12:44 AM |
| Remove diagonal movement in an A* algorithm. |
|
|
| Report Abuse |
|
|
TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 29 Dec 2011 07:35 PM |
@Merlin, A* makes the movement all at once, by detecting the pathway first. This does it step by step. |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 29 Dec 2011 07:51 PM |
| If you created a circle of points from different nodes and used raycasting to decide where they end, then you could just have a very fast version of Dijkstra's algorithm solve the shortest path, rather than having something grid-based where it takes 2 thousand calculations to solve one path. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 29 Dec 2011 08:19 PM |
| No, because it would pick the shortest path. |
|
|
| Report Abuse |
|
|
Jaccob
|
  |
| Joined: 19 Oct 2008 |
| Total Posts: 986 |
|
|
| 29 Dec 2011 08:27 PM |
| And what happens if it's trapped and can't move anywhere. It can't find any possible solutions so therfore it breaks :P |
|
|
| Report Abuse |
|
|
TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 29 Dec 2011 08:28 PM |
@Jaccob, the only time that will happen is if its surrounded by a box, which every ai wouldn't be able to find a solution out of. |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 29 Dec 2011 08:35 PM |
Just fiddling with the idea in my mind a bit... it will get trapped in this situation:
|¯ ................. _|
I will just keep going back and forth. And that's a fairly common situation too, so you'd have to deal with that. |
|
|
| Report Abuse |
|
|
TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 29 Dec 2011 11:19 PM |
@Stravant, Well, it would only travel about 3/4 of the way.. Soo..? _ |¯ .............. _| . .
:D? |
|
|
| Report Abuse |
|
|
TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 29 Dec 2011 11:19 PM |
| Darn forum no allow whitespacing T-T |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 29 Dec 2011 11:26 PM |
| Oh, whoops, forgot to take that into account. Hmm, I'm pretty sure there's still a way to trap it, but I can't figure it out at the moment. |
|
|
| Report Abuse |
|
|
TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 29 Dec 2011 11:47 PM |
There is, for example.
______ | X | |_ _|
I hope roblox showed this properly, but basically of the destination is surrounded by a box and the entrance is in the middle of one of the sides, it wont be able to get in. It'll run an endless square around it. |
|
|
| Report Abuse |
|
|
TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 29 Dec 2011 11:51 PM |
Although a possible fix would be to make it so a constant coroutine is running and raycasting towards to destination. This way while its walking in front of the door, the script would be able to cast from the torso to X without a problem, and force itself to walk in that direction.
At least in my mind it works.. ^_^? |
|
|
| Report Abuse |
|
|
Jopc67
|
  |
| Joined: 10 Oct 2009 |
| Total Posts: 5550 |
|
|
| 30 Dec 2011 01:35 AM |
| You need it to raycast in all directions, or the directions that are relevant for the situation, to not get trapped. It'll have to to it probably every half second or shorter. :/ (Lag anyone?) |
|
|
| Report Abuse |
|
|
TimeShop
|
  |
| Joined: 24 Nov 2010 |
| Total Posts: 1274 |
|
|
| 30 Dec 2011 01:52 AM |
@Stravant, By the way, with your original concept of trapping it, the AI would be able to get out, since it would refuse to go left because it is possible for it to go down. |
|
|
| Report Abuse |
|
|