Problems with Slug AI

L

LilRony

Guest
/quality title

Jokes aside, I have a problem with an enemy AI that I'm working on. What I'm trying to get is a slug character that moves uniquely.

The way he moves is based on his animation. When the slug is stretched out, he moves a little bit. When he's contracting, he stops moving. This is how I have it working:

moveSpd = 1 * facing;
image_speed = 0.1;
sprite_index = spr_SlugNormal;

// based on slug animation, which frames to move
if (image_index == 0 || image_index == 3) {
hspd = moveSpd;
}else{
hspd = 0;
}

...Now this works correctly, but only for a little bit. After he moves for a little while (about 5 seconds), he just... stops. I don't understand. If I'm just doing something wrong with my if-else nesting, please tell me.

Thanks!
 
This appears to be a math epsilon and floating point precision problem. If you round some way the image_index, it should take care of the problem:

Code:
var _f = floor(image_index);
if (_f == 0 or _f == 3)
{
  hspeed = 2;
  }else{
  hspeed = 0;
}
 
L

LilRony

Guest
This appears to be a math epsilon and floating point precision problem. If you round some way the image_index, it should take care of the problem:

Code:
var _f = floor(image_index);
if (_f == 0 or _f == 3)
{
  hspeed = 2;
  }else{
  hspeed = 0;
}
Oh, okay. I tried it and it works now, thanks much!
 
Top