Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
Lapsa's very own thread
by rki. 06/19/24 11:27
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,227 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mino, squik, AemStones, LucasJoshua, Baklazhan
19061 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Please help me with this #306161
01/20/10 08:47
01/20/10 08:47
Joined: Dec 2009
Posts: 24
DirtyDhan Offline OP
Newbie
DirtyDhan  Offline OP
Newbie

Joined: Dec 2009
Posts: 24
Can any one please give me some code for enemy A.I. that makes the enemy walk straight to the player. I am doing versus game and I need a starting code to program the A.I. I'm really lost at what to do right now.

Here is my enemy action code

============================================================

action player_cb()
{

//ENEMY IS STANDING ON GROUND
VECTOR vFeet;
vec_for_min(vFeet,me);
set(my,FLAG2);
my.ESTATE = 1;
//ENEMY IS IDLE
if(my.ESTATE == 1)
{
my.EANIMATION += 10 * time_step;
ent_animate(my, "idle", my.EANIMATION, ANM_CYCLE);
var dist_between = pos_player - pos_cb;
if(dist_between != 0)
{
my.EANIMATION = 0;
my.ESTATE = 2;
}
else if(dist_vs == 0)
{
my.EANIMATION = 0;
my.ESTATE = 1;
}
}


if(my.ESTATE == 2)
{
var distance = (dist_vs)*5*time_step;
c_move(my, vector(0,distance,0), NULL, NULL);

walk_percentage -= 3*distance;
ent_animate(my,"walk",walk_percentage,ANM_CYCLE);
my.EANIMATION = 0;
my.ESTATE = 3;
}
if(my.ESTATE == 3)
{
my.EANIMATION = 0;
my.ESTATE = 1;
}

============================================================
got so many error there. I cant run it.


If you do not know where you are . . .
Ask a villager.
Re: Please help me with this [Re: DirtyDhan] #306162
01/20/10 08:52
01/20/10 08:52
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
This code is nonsense. There is no loop, no wait etc.

Read the tutorial, you must understand how actions work before you can write them.

Re: Please help me with this [Re: Petra] #306170
01/20/10 10:31
01/20/10 10:31
Joined: Dec 2009
Posts: 24
DirtyDhan Offline OP
Newbie
DirtyDhan  Offline OP
Newbie

Joined: Dec 2009
Posts: 24
Thx for the reply. How bout tis one.

========================================================================
action player_cb()
{
var pos_cb = vector(my.x, my.y, my.z);
//ENEMY IS STANDING ON GROUND
VECTOR vFeet;
vec_for_min(vFeet,me);
set(my,FLAG2);
my.ESTATE = 1;
//ENEMY IS IDLE
if(my.ESTATE == 1)
{
while(1)
{
my.EANIMATION += 10 * time_step;
ent_animate(my, "idle", my.EANIMATION, ANM_CYCLE);
if(vec_dist(my.x,player.x)<900)
{
my.EANIMATION = 0;
my.ESTATE = 2;
}
wait(1);
}
}
if(my.ESTATE == 2)
{
while(1)
{
var distance = my.x *5*time_step;
c_move(my, vector(0,distance,0), NULL, NULL);
walk_percentage -= 3*distance;
ent_animate(my,"walk",walk_percentage,ANM_CYCLE);
my.EANIMATION = 0;
my.ESTATE = 3;
wait(1);
}
}
if(my.ESTATE == 3)
{
my.EANIMATION = 0;
my.ESTATE = 1;
}
}
============================================================================

Please tell me where I went wrong or whats lacking.

Really appreciate every reply.


If you do not know where you are . . .
Ask a villager.
Re: Please help me with this [Re: DirtyDhan] #306184
01/20/10 11:58
01/20/10 11:58
Joined: Dec 2009
Posts: 24
DirtyDhan Offline OP
Newbie
DirtyDhan  Offline OP
Newbie

Joined: Dec 2009
Posts: 24
I updated my code

===============================================================================
action player_cb()
{
var pos_cb = vector(my.x, my.y, my.z);
//ENEMY IS STANDING ON GROUND
VECTOR vFeet;
vec_for_min(vFeet,me);
set(my,FLAG2);
my.STATE = 1;
//ENEMY IS IDLE
if(my.STATE == 1)
{
c_scan(my.x,my.pan,vector(900,900,900),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
while(1)
{
my.ANIMATION += 10 * time_step;
ent_animate(my, "idle", my.ANIMATION, ANM_CYCLE);
if(you)
{
my.ANIMATION = 0;
my.STATE = 2;
}
wait(1);
}
}
if(my.STATE == 2)
{
var agwat = vec_dist(my.x, your.x);


while(1)
{
if(agwat > 900)
{
ent_animate(my,"walk",walk_percentage,ANM_CYCLE);
my.ANIMATION = 0;
if(agwat == 0)
{
my.ANIMATION = 0;
my.STATE = 3;
}
}
wait(1);
}

}
if(my.STATE == 3)
{
my.ANIMATION = 0;
my.STATE = 1;

}
}

============================================================================

Enemy detects my presence but it only stays in idle animation. Unless the distance between the two is reduced to 0, the enemy should be on walking state but it still stays in idle state.


If you do not know where you are . . .
Ask a villager.
Re: Please help me with this [Re: DirtyDhan] #306187
01/20/10 12:13
01/20/10 12:13
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Suprised this even compiled...

1)'var pos_cb = vector(my.x, my.y, my.z);' >>> the function 'vector' returns a VECTOR*, not a var.

2)It is in the 'idle' state forever because you are stuck inside an infinite loop. You need to either replace 'while(1)' with a condition like 'while(my.STATE != 2)' or add a 'break;' statement somewhere within the loop, so it can break out of the loop and continue executing the statements below the loop, eg. the distance test and walking animation.

Last edited by DJBMASTER; 01/20/10 12:19.
Re: Please help me with this [Re: DJBMASTER] #306190
01/20/10 12:19
01/20/10 12:19
Joined: Dec 2009
Posts: 24
DirtyDhan Offline OP
Newbie
DirtyDhan  Offline OP
Newbie

Joined: Dec 2009
Posts: 24
oh i forgot to remove it hehe.


If you do not know where you are . . .
Ask a villager.
Re: Please help me with this [Re: DirtyDhan] #306191
01/20/10 12:22
01/20/10 12:22
Joined: Dec 2009
Posts: 24
DirtyDhan Offline OP
Newbie
DirtyDhan  Offline OP
Newbie

Joined: Dec 2009
Posts: 24
ok I've already remove that pos_cb thingy. I still get the same results.


If you do not know where you are . . .
Ask a villager.
Re: Please help me with this [Re: DirtyDhan] #306196
01/20/10 12:42
01/20/10 12:42
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Have you changed the infinite loop?

Last edited by DJBMASTER; 01/20/10 12:43.
Re: Please help me with this [Re: DJBMASTER] #306203
01/20/10 14:19
01/20/10 14:19
Joined: Dec 2009
Posts: 24
DirtyDhan Offline OP
Newbie
DirtyDhan  Offline OP
Newbie

Joined: Dec 2009
Posts: 24
Ya, I tried change it. I think the problem seems to be that the program wont enter state2. I updated my code again, still get same result.

================================================================================

action player_cb()
{
ENTITY* enemy = NULL;
//ENEMY IS STANDING ON GROUND=================================================================
VECTOR vFeet;
vec_for_min(vFeet,me);
set(my,FLAG2);
my.STATE = 1;
//ENEMY IS IDLE===============================================================================
if(my.STATE == 1)
{
//DETECT THE ENEMY============================================================================
c_scan(my.x,my.pan,vector(900,0,0),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
while(1)
{
my.ANIMATION += 10 * time_step;
ent_animate(my, "idle", my.ANIMATION, ANM_CYCLE);
if(you)
{
my.ANIMATION = 0;
my.STATE = 2;
enemy = your.PLAYER;
}
wait(1);
}
}
//PERFORM WALK ANIMATION======================================================================
if(my.STATE == 2)
{
VECTOR vDirection;
ANGLE vTargetAngle;
vec_diff(vDirection,enemy.x,my.x);
vec_to_angle(vTargetAngle,vDirection);
my.pan += time_step * sign(ang(vTargetAngle.pan - my.pan));
var dist = vec_dist(my.x, your.x);

while(1)
{
if(dist > 0 || dist < 0)
{
var distance = 5*time_step;
c_move(me, vector(distance,0,0), NULL, GLIDE);
walk_percentage += 2* distance;
ent_animate(my,"walk",walk_percentage,ANM_CYCLE);

if(dist == 0)
{
my.ANIMATION = 0;
my.STATE = 3;
}
}
wait(1);
}

===============================================================================

I tried putting in some program that may cause errors in state2, still the program was able to run. I think the problem is in

==========================================================

if(you)
{
my.ANIMATION = 0;
my.STATE = 2;
enemy = your.PLAYER;
}
==========================================================

because the it doesnt seem to detect (you) thats why it doesnt enter the if statement and only perform the idle state. I wonder whats the problem? . . .


If you do not know where you are . . .
Ask a villager.
Re: Please help me with this [Re: DirtyDhan] #306206
01/20/10 14:44
01/20/10 14:44
Joined: Dec 2009
Posts: 24
DirtyDhan Offline OP
Newbie
DirtyDhan  Offline OP
Newbie

Joined: Dec 2009
Posts: 24
ALRIGHT!!! Problem solved!!!!

problem is here
===========================================================
c_scan(my.x,my.pan,vector(900,0,0),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
===========================================================
It should have been
===========================================================
c_scan(my.x,my.pan,vector(900,0,900),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
===========================================================

my level was facing backwards. I didnt notice that xz wa back not front T,T.

Many thx for your replies sir.


If you do not know where you are . . .
Ask a villager.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1