Working on a simple patrol "AI"

Posted By: Valdsator

Working on a simple patrol "AI" - 07/10/10 06:02

I am now working on the enemies in my side scroller game. Currently, I am trying to get them to patrol a certain area of the level, and when they spot the player, they go after him (and some, shoot him) until a certain point.

-Skip until questions if you want-

Now, I'm not going to start coding tons of things to make this AI work. This is my first 3D game using Gamestudio, and first 3D game using any code. My plan is to have each enemy between 2 "patrol points." Simple white boxes that are passable and invisible in-game. The enemy is always moving, but whenever it reaches a patrol point, it turns around (with a simple pan function).

The enemy will have 3 modes (or more depending on it's type). Patrol, Caution, and Return. Patrolling is just that. Caution, is when the player enters a certain range, and the enemy begins chasing him. When in this mode, the enemy does not notice the patrol points. It will go after the player until reaching a Caution Point (another box). If it reaches a Caution Point, it will go in to Return mode.

Return mode is when the enemy loses interest in the player and begins returning to its Origin Point, the place it spawned (in between the Patrol Points). It will not notice Patrol Points until it reaches the Origin Point, where it will go back to Patrol mode.

Now, I've been trying to get one part of this working (patrolling), through Flags and other ways which don't work well. With this, I realized I needed to use Skills, but I need some help with them.

-Questions-

First, I want to make the Patrol Points a certain Skill. Does it matter what Skill I choose for this? Is there some rule where Skill22 has to be the player? Should I go about setting the skill in WED or SED?

Next, how should I have the enemy's check for touching a Patrol Point? C_trace and c_scan are slow, is there any other way?

Once the enemy knows something is nearby it, how do I have it check if the thing it's touching has a certain Skill set to a certain number? I tried using c_trace and then
if(you.skill22 == 1)
but that brought up an error in the enemy's action.

I'm sure I'm missing something, but currently those are the questions I can think of that I need help with. Sorry for the long post, and thanks in advance (I apologize if I don't understand certain things that people explain, I'm not too great with C-lite yet :P).
Posted By: JoGa

Re: Working on a simple patrol "AI" - 07/10/10 06:58

-
Quote:
Remarks:
Entity.skill1..entity.skill20 are used for entering default properties in WED. Entity.skill21..entity.skill50 are used by the template scripts, except for entity.skill41..Entity.skill44, which are used for shaders. Entity.skill51..entity.skill100 are free for the user.
-manual

- Yoou can search in the manual for a patrol-example, search for "path_scan", there is a example of patroling, if you work in WED with paths, you can use this way of patroling:
Code:
// move along a path loop
 // uses _FORCE, _MOVEMODE
 action patrol_path()
 {
 // attach entity to nearest path
  result = path_scan(me,my.x,my.pan,vector(360,180,1000));
  if (result == 0) { return; } // no path found
 
 // find first waypoint
  var node = 1; // start at first node
  path_nodepos(my,node,my._TARGET_X);
 
  while (my._MOVEMODE)
  {
 // find direction
    result = vec_to_angle(angle,vec_diff(temp,my._TARGET_X,my.x));
 
 // near target? Find next waypoint of the path
    if (result < 25) {
      node = path_nextnode(my,node,1);
      path_nodepos(my,node,my._TARGET_X);
    }
 
 // turn and walk towards target
    actor_turnto(angle.PAN);
    actor_moveahead(MY._FORCE);
    wait(1);
  }
}


- If the enemy checks, if something touching him, you can set entity.enable_entity = on
Code:
my.ENABLE_ENTITY = ON; // make entity sensitive for entity collision
  my.event = bounce_event;


and in the function bounce_event, the other entity is called by "you", so you can check
Code:
define our_hero, 1;
function bounce_event()
{
  if(you.skill22=our_hero)
  {
    //attack
  }
}


I dont test it, it's just theory, but I hope, it helps =)
Posted By: 3run

Re: Working on a simple patrol "AI" - 07/10/10 16:29

Tell more about your sidescrolling game, player move on the fixed line (straight forward and backward), or he can move around like in Georges sidescroller game? I've made some simple AI that move around the level, for fixed on the straight line moving games, some of them even shoot player, you can find them in my project GRAVITY in script. I didn't put them in demo levels (only turrent), I hope that it will help you bro. PM me if you need some help.
Posted By: Valdsator

Re: Working on a simple patrol "AI" - 07/13/10 18:15

Currently, using paths is a bit too complicated for me, and I'd like to attempt to make my own sort of AI, even if it's slow and inefficient.

This side scroller is a bit like Duke Nukem: Manhattan Project. You move left or right, shoot enemies, and jump around. I just need those questions in the original post answered, and I'll see what I can make.
Posted By: tD_Datura_v

Re: Working on a simple patrol "AI" - 07/14/10 14:08

Quote:
First, I want to make the Patrol Points a certain Skill.

Quote:
Does it matter what Skill I choose for this?

To some extent, the skill selection is left up to the "client programmer".
Here a "client programmer" is defined as a lite-c programmer for a game made with 3D Gamestudio.
The "client programmer" might be you.
You might select any ENTITY skill number not already assigned or used for some other purpose.
Quote:
Is there some rule where Skill22 has to be the player?

(I do not know of any such rule.) Such rules might be set by the "client programmer".
Quote:
Should I go about setting the skill in WED or SED?

The first 20 or so skills might be set in WED. However, in the case of a simple patrol AI, a skill or skills might be more likely set via script using lite-c and SED.
Quote:
Next, how should I have the enemy's check for touching a Patrol Point?

The answer to that might depend upon the definition of "Patrol Point".
If a "Patrol Point" is an path, than path instructions might be used. If it is an ENTITY, than c_scan or other instructions might be used.
Quote:
Once the enemy knows something is nearby it, how do I have it check if the thing it's touching has a certain Skill set to a certain number?

If c_scan is used with the enemy to detect a something (ENTITY) nearby, than an event might be fired, and inside that event the "you" pointer might be set to that nearby thing (ENTITY). Skills of that "you" pointer might be evaluated.
Posted By: Valdsator

Re: Working on a simple patrol "AI" - 07/14/10 22:52

Originally Posted By: tD_Datura_v

If c_scan is used with the enemy to detect a something (ENTITY) nearby, than an event might be fired, and inside that event the "you" pointer might be set to that nearby thing (ENTITY). Skills of that "you" pointer might be evaluated.


Thanks for the answers. What I'm wondering about this though, is what sort of code should I use to check if "you" has a certain skill set to a certain number? Like I said, I used if(you.skill22 == 1){ but that crashed the enemy action. Is there some other way I check for the skill, or am I just typing something incorrectly?
Posted By: Liamissimo

Re: Working on a simple patrol "AI" - 07/14/10 23:01

Just if(you) and then if(you.skill22 == 1). Because if there is no you it crashes I think grin
Posted By: Valdsator

Re: Working on a simple patrol "AI" - 07/15/10 03:49

Ah, I see. I was actually thinking if that was the problem, just didn't know how to check if you was being used.

Thanks. laugh
Posted By: Valdsator

Re: Working on a simple patrol "AI" - 07/17/10 04:53

Alright, I've done some work and got the enemy to begin moving and turning every time it touches a patrol point. But I've run in to a problem. Bullets push the enemy back a little (which sometimes causes a bug where the enemy doesn't notice the patrol point), and a good way to fix that was to just make it's c_move ignore FLAG2, which the bullets were set to. But, the player is also set to FLAG2, making the enemy move through the player.

Question:
Is it possible to somehow have the c_move ignore a different flag? FLAG3 for instance? If so, how?

Thanks in advance.
Posted By: ghdfans2010

Re: Working on a simple patrol "AI" - 07/17/10 09:09

In my opinion,I'd like to attempt to make my own sort of AI, even if it's slow and inefficient.How do you think?

Posted By: Valdsator

Re: Working on a simple patrol "AI" - 07/20/10 06:48

Bump.

Originally Posted By: Valdsator
Question:
Is it possible to somehow have the c_move ignore a different flag? FLAG3 for instance? If so, how?

Thanks in advance.

Posted By: ghdfans2010

Re: Working on a simple patrol "AI" - 10/20/10 08:34

Hello, I am back!
© 2024 lite-C Forums