2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Working on a simple patrol "AI"
#332503
07/10/10 06:02
07/10/10 06:02
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
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).
|
|
|
Re: Working on a simple patrol "AI"
[Re: Valdsator]
#332505
07/10/10 06:58
07/10/10 06:58
|
Joined: Dec 2003
Posts: 988 Germany, Magdeburg
JoGa
User
|
User
Joined: Dec 2003
Posts: 988
Germany, Magdeburg
|
- 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:
// 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
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
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 =)
|
|
|
Re: Working on a simple patrol "AI"
[Re: Valdsator]
#333162
07/14/10 14:08
07/14/10 14:08
|
Joined: Dec 2005
Posts: 116
tD_Datura_v
Member
|
Member
Joined: Dec 2005
Posts: 116
|
First, I want to make the Patrol Points a certain Skill. 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. 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". 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. 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. 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.
|
|
|
Re: Working on a simple patrol "AI"
[Re: tD_Datura_v]
#333226
07/14/10 22:52
07/14/10 22:52
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
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?
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|