Page 2 of 3

Re: AI Help

PostPosted: Wed May 12, 2010 6:48 pm
by Hblade
You mean per frame lol, 4 pxels a second would be insanely fast :o

Re: AI Help

PostPosted: Wed May 12, 2010 8:30 pm
by linkshards
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. @_@

Re: AI Help

PostPosted: Wed May 12, 2010 8:46 pm
by Hblade
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

Re: AI Help

PostPosted: Wed May 12, 2010 9:22 pm
by linkshards
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. :(

Re: AI Help

PostPosted: Thu May 13, 2010 1:44 pm
by Hblade
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

Re: AI Help

PostPosted: Thu May 13, 2010 4:39 pm
by linkshards
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.

Re: AI Help

PostPosted: Thu May 13, 2010 4:53 pm
by Hblade
I'll take a look later :D

Re: AI Help

PostPosted: Thu May 13, 2010 5:04 pm
by linkshards
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;
                                                      }
            }

Re: AI Help

PostPosted: Thu May 13, 2010 6:49 pm
by Hblade
I'll have to make a demo some time :D

Re: AI Help

PostPosted: Fri May 14, 2010 2:11 am
by linkshards
Somethin' like this. How the soldiers know where the player is and face toward him.


Re: AI Help

PostPosted: Fri May 14, 2010 2:58 am
by DST
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;

Re: AI Help

PostPosted: Fri May 14, 2010 3:06 am
by Hblade
DST, very nice code! :D But I think you forgot something - animation?

Re: AI Help

PostPosted: Fri May 14, 2010 3:23 am
by DST
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?

Re: AI Help

PostPosted: Fri May 14, 2010 3:53 am
by linkshards
But I wouldn't need to make a scale if I have a MoveTo method being used would I?

Re: AI Help

PostPosted: Fri May 14, 2010 3:56 am
by DST
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.