Looking for: math, enemy movement

M

mamacato

Guest
Hi gang,

I'm looking for some tutorials (videos, source files, or just code) on enemy movement. Specifically the math involved in making interesting enemy movements. I'm new to programming, so my math skills are rather rusty. I'm starting to understand how the use of variables and math equations are needed to make interesting "AI". If there are some examples out there that I can study, I'd be most appreciative if someone pointed me in the right direction. I don't mind shelling over some clams either. And, er.. Any style of game would do since I'm just looking at the math to learn new things.

( ˘ ³˘)
 
T

Taddio

Guest
Well, the principle is pretty much the same for every game, in terms of movement.
You can move x pixels per step (one game frame) on both x and y axis (and z too, for 3D).
The controls will change for sure, eg. the up key would make you jump then fall with gravity in a side-scrolling platformer, but would make you walk to the top of your screen in a top-down RPG.
For the basic AI, you can then implement a STATE MACHINE, where you would define states to a bunch of condition, eg.
Code:
if(distance_to_object(obj_player)<=100) {
enemy_state = CHASING;
}
And then you have a SWITCH statement like
Code:
switch(enemy_state){
       case IDLE:
            //Do idle stuff
         break;
        case CHASING:
            //Moves towards player
          break;
         case ATTACKING:
            //Attack player
           break;

//And so on for all of your potential enemy states
}
As for the maths themselves, I won't say you don't need them (it does helps a lot, obviously), but GM has a lot of it covered already in it's built-in functions, and you can look up EASING AND TWEENING SCRIPTS (free on the marketplace), which outputs the value of a function with the parameters you input (cubic, quad, sine, cos, elastic, etc.), which are very useful, as GM only has the function lerp() which is like that, but only uses a linear function.

Edit: Cool, je viens de voir que t'es d'la belle province aussi. Chuis natif de l'Abitibi!
 
Last edited by a moderator:
M

mamacato

Guest
reply to Taddio:

You've said a lot! Thanks. ,,^. . ^,,~
 
Top