AI Help

Talk about making games.

Re: AI Help

Postby Hblade » Wed May 12, 2010 6:48 pm

You mean per frame lol, 4 pxels a second would be insanely fast :o
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: AI Help

Postby linkshards » Wed May 12, 2010 8:30 pm

Hblade wrote:hehe, dont worry link, I'll help as much as possible :D

I'm not sure if this will work, but try using this: :D
Code: Select all
if (animpos == 0)
{
    ChangeAnimation
}
if (animpos == nframes)
{
    animpos = 0;
}


But put it with the if (x<hero.x) and stuff, so put it under the x+=4; and remove the old ChangeAnimation :D

Wait wait, so am I using an operand for this? Or am I opening another bracket?

Like this?:
Code: Select all
if(x>hero.x){
    if(animpos == 0{
    ChangeAnimation("Event Actor", "mon1walkleft1", NO_CHANGE);
}
   if(animpos == nframes)
animpos 0 ;
}

Or like this?:
[code]
if(x>hero.x&&animpos ==0)
...


Sorry, I'm just so confused. @_@
User avatar
linkshards
 
Posts: 45
Joined: Tue Apr 27, 2010 3:40 am
Location: Cibolo, Texas
Score: 1 Give a positive score

Re: AI Help

Postby Hblade » Wed May 12, 2010 8:46 pm

Like this :D

Code: Select all
if(x>hero.x){
    if(animpos == 0{
    ChangeAnimation("Event Actor", "mon1walkleft1", NO_CHANGE);
}
   if(animpos == nframes)
animpos 0 ;
}
}


You were right the first time :3
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: AI Help

Postby linkshards » Wed May 12, 2010 9:22 pm

Alright I tested it. Same thing sadly. :(

Here's what I have.
Code: Select all
MoveTo("Event Actor", 0.000000, 0.000000, 4.000000, "hero", "");

if(x>hero.x){
    if(animpos == 0){
    ChangeAnimation("Event Actor", "mon1walkleft1", NO_CHANGE);
            }
                if(animpos == nframes){
                animpos = 0 ;
                                      }
            }
 
                    else if(x<hero.x){
                        if(animpos == 0){
                ChangeAnimation("Event Actor", "mon1walkright1", NO_CHANGE);
                                        }
                                        if(animpos == nframes){
                                            animpos = 0;
                                                              }
                                     }
 
 
            else if(y>hero.y){
                if(animpos == 0){
                ChangeAnimation("Event Actor", "mon1walkfront1_seq",NO_CHANGE);
                                }
                                if(animpos == nframes){
                                    animpos = 0;
                                                      }
                                          }
            else if(y<hero.y){
                if(animpos == 0){
                ChangeAnimation("Event Actor", "mon1walkup1_seq", NO_CHANGE);
                                }
                                if(animpos == nframes){
                                    animpos = 0;
                                                      }
            }


I really can't figure out what I'm doing wrong. >_<
You guys understand what I'm trying to do though right?

EDIT: Man, I just have so much to work on. I just can't get any code to work right. Not even pausing. Hblade, help. :(
User avatar
linkshards
 
Posts: 45
Joined: Tue Apr 27, 2010 3:40 am
Location: Cibolo, Texas
Score: 1 Give a positive score

Re: AI Help

Postby Hblade » Thu May 13, 2010 1:44 pm

Ahhhhh! okay! :D here ya go :3
Replace your old code with this :D (It's un tested though :o)
Code: Select all
MoveTo("Event Actor", 0.000000, 0.000000, 4.000000, "hero", "");

if(x>hero.x){
    if(animpos==0){
    ChangeAnimation("Event Actor", "mon1walkleft1", NO_CHANGE);
            }
                if(animpos == nframes){
                animpos = 0 ;
                                      }
            }

if(x<hero.x){
                        if(animpos==0){
                ChangeAnimation("Event Actor", "mon1walkright1", NO_CHANGE);
                                        }
                                        if(animpos == nframes){
                                            animpos = 0;
                                                              }
                                     }


if(y>hero.y){
                if(animpos==0){
                ChangeAnimation("Event Actor", "mon1walkfront1_seq",NO_CHANGE);
                                }
                                if(animpos == nframes){
                                    animpos = 0;
                                                      }
                                          }
if(y<hero.y){
                if(animpos==0){
                ChangeAnimation("Event Actor", "mon1walkup1_seq", NO_CHANGE);
                                }
                                if(animpos == nframes){
                                    animpos = 0;
                                                      }
            }


I hope that helps, other than that I dont see the error either :o
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: AI Help

Postby linkshards » Thu May 13, 2010 4:39 pm

The code makes the up and the down animations work, but not the right nor the left.

Yesterday, I sat at my computer for about 8 hours trying to get the code to work right.

I don't have the code with me right nao to show you because I am at school and I am still working on code using the school's Drive.

However the code I was using involved two statements that must be true to make a direction work that I can ALMOST get right, but using the absolute values of x and y coordinates.
User avatar
linkshards
 
Posts: 45
Joined: Tue Apr 27, 2010 3:40 am
Location: Cibolo, Texas
Score: 1 Give a positive score

Re: AI Help

Postby Hblade » Thu May 13, 2010 4:53 pm

I'll take a look later :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: AI Help

Postby linkshards » Thu May 13, 2010 5:04 pm

Alright, here's the code I was messing with at home. (Kind've. The one I was messing with didn't have the nframe stuff & animpos stuff in it.)

Code: Select all
MoveTo("Event Actor", 0.000000, 0.000000, 2.000000, "player", "");

if((x>player.x)&&(x>(abs(player.y)))){
    if(animpos==0){
    ChangeAnimation("Event Actor", "leftarrow", NO_CHANGE);
            }
                if(animpos == nframes){
                animpos = 0 ;
                                      }
            }

if((x<player.x)&&((abs(x))>(abs(player.y)))){
                        if(animpos==0){
                ChangeAnimation("Event Actor", "rightarrow", NO_CHANGE);
                                        }
                                        if(animpos == nframes){
                                            animpos = 0;
                                                              }
                                     }


if((y>player.y)&&(y>=(abs(player.x)))){
                if(animpos==0){
                ChangeAnimation("Event Actor", "downarrow",NO_CHANGE);
                                }
                                if(animpos == nframes){
                                    animpos = 0;
                                                      }
                                          }
if((y<player.y)&&(abs(y))>=(abs(player.x))){
                if(animpos==0){
                ChangeAnimation("Event Actor", "uparrow", NO_CHANGE);
                                }
                                if(animpos == nframes){
                                    animpos = 0;
                                                      }
            }
User avatar
linkshards
 
Posts: 45
Joined: Tue Apr 27, 2010 3:40 am
Location: Cibolo, Texas
Score: 1 Give a positive score

Re: AI Help

Postby Hblade » Thu May 13, 2010 6:49 pm

I'll have to make a demo some time :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: AI Help

Postby linkshards » Fri May 14, 2010 2:11 am

Somethin' like this. How the soldiers know where the player is and face toward him.

User avatar
linkshards
 
Posts: 45
Joined: Tue Apr 27, 2010 3:40 am
Location: Cibolo, Texas
Score: 1 Give a positive score

Re: AI Help

Postby DST » Fri May 14, 2010 2:58 am

In this example, i named the animations 0, 1, 2, 3. In this way, if the boss changes animation type, like a soldier turning into a werewolf, i could name them werewolf0, werewolf1, werewolf2, and before my sprintf, i just paste 'werewolf' in front of dirs. (or just flashing from being hit).

Code: Select all
char dirs[4]="";                            //create an empty string to use for animation

angle=direction(x, y, hero.x, hero.y);     //find angle to player

dir=round(angle/90); //find animation direction based on angle, where dir is a variable you made.

if(angle>315){dir=0;}                              //compensate for angles between 315 & 0

if(dir!=prevdir){//if our dir has changed from last frame, where prevdir is a variable you made
sprintf(dirs, "%i", dir);                           //write our direction to the string 'dirs'.
ChangeAnimation("Event Actor", dirs, FORWARD);  //change to animation matching 'dir'.
}

prevdir=dir;


Then after that, If the enemy can move in any direction, use
directional_velocity=speed; //where speed is your desired velocity.

Else if the enemy can only move UDLR, use
directional_velocity=speed;
angle=dir*90;
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: AI Help

Postby Hblade » Fri May 14, 2010 3:06 am

DST, very nice code! :D But I think you forgot something - animation?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: AI Help

Postby DST » Fri May 14, 2010 3:23 am

What do you mean?

we only change animation on a new direction change, in which case, resetting it won't be noticeable. Otherwise, he just keeps walking, and the animation moves forward.

IF you wanted him to animate at the speed of his walking, you'd devise a scale. Let's use 4 pixels = 1 footstep.
Then you'd always change animation to STOPPED.

So
Code: Select all
if(distance(x, y, xprev, yprev)>=4){
animpos++;
xprev=x;
yprev=y;
animpos=iLoop(animpos, 0, nframes); //see the global function for this below
}


Code: Select all
int iLoop(int x1, int ll, int ul){
if(x1>ul){x1=ll;} //if it's greater than the Upper Limit, it = Lower Limit
else if(x1<ll){x1=ul;}//if it's smaller than the Lower Limit, it = Upper Limit
return x1;
}


So changing direction changes animation, which is a step. Moving 4 pixels increments animation, so a fast moving creature will appear to run.


Is this what you meant?
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: AI Help

Postby linkshards » Fri May 14, 2010 3:53 am

But I wouldn't need to make a scale if I have a MoveTo method being used would I?
User avatar
linkshards
 
Posts: 45
Joined: Tue Apr 27, 2010 3:40 am
Location: Cibolo, Texas
Score: 1 Give a positive score

Re: AI Help

Postby DST » Fri May 14, 2010 3:56 am

The scale is arbitrary. You already have one just by having an animation, with an animation speed, in the first place.
But with normal animation speed is static.

by scale, i just meant 1 footstep=4 pixels.

using moveto doesn't change anything, except for rendering the "directional_Velocity=" line obsolete.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

PreviousNext

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest