3 registered members (NewbieZorro, TipmyPip, 1 invisible),
19,045
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: AI search food help
[Re: Rei_Ayanami]
#279190
07/16/09 20:33
07/16/09 20:33
|
Joined: Jul 2004
Posts: 1,205 Greece
LarryLaffer
Serious User
|
Serious User
Joined: Jul 2004
Posts: 1,205
Greece
|
Your code is working like it should. It picks up the only food in the level, and since there's no more, it waits on that while(grub==NULL) line. What is it that you're trying to achieve?
If you add more food sources in your level, you'll have to face a little problem. If you assign all your food models to the same action, then the grub pointer will be assigned to the first food, then it will be overwritten and assigned to the second food source, etc. So when the game starts, the grub pointer will be assigned to the last food model. Your AI will go and eat it which makes the pointer NULL.
Take some time and learn about arrays so you can store ALL food pointers/handles to them, so if you eat the last one, it will go look for other food pointers in that array.
Cheers, Aris
|
|
|
Re: AI search food help
[Re: awstar]
#279255
07/17/09 02:27
07/17/09 02:27
|
Joined: Jul 2004
Posts: 1,205 Greece
LarryLaffer
Serious User
|
Serious User
Joined: Jul 2004
Posts: 1,205
Greece
|
Well, for starters replace this:
///////////////////////////////////////////
while (grub == null) //////<---------this code gets rid of empty pointer error, but freezes the AI after he picks up the food.
{wait (1);}
if (vec_dist (my.x, grub.pos) < 200) // the player approaches the food
{
// name_ent2();
vec_set(temp, grub.pos);
vec_sub(temp, my.pos);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac smile
walk_speed.x = 10 * time;
walk_speed.y = 0;
walk_speed.z = 0;
ent_move(creature_distance, nullvector);
ent_cycle("walk", my.skill19); // play walk frames animation
my.skill19 += 5 * time; // "walk" animation speed
// ent_playsound (my, walk_snd, 50);
wait (1);
}
with this:
///////////////////////////////////////////
if (grub != null)
{
if (vec_dist (my.x, grub.pos) < 200) // the player approaches the food
{
// name_ent2();
vec_set(temp, grub.pos);
vec_sub(temp, my.pos);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac smile
walk_speed.x = 10 * time;
walk_speed.y = 0;
walk_speed.z = 0;
ent_move(creature_distance, nullvector);
ent_cycle("walk", my.skill19); // play walk frames animation
my.skill19 += 5 * time; // "walk" animation speed
// ent_playsound (my, walk_snd, 50);
wait (1);
}
}
This will prevent it from crashing or freezing after the bots gets the food, but you still have problems if multiple food models are in the level (all but one will be ignored) Teach yourself about arrays and you may also want to consider moving from c-script to lite-c so you can use ENTITY* arrays instead of having to deal with handles. Cheers, Aris
|
|
|
|