this is a snippet from my AI state machine. I had monsters walking around randomly fine before but that was with test code where they just instantly faced the way they were supposed to be headed and walked in that direction for a bit, even through walls.
Now I choose their next destination point taking stuff like walls into account, the destination point is set in another case statement and stored in MonsterStack[n].dx and MonsterStack[n].dz - i can confirm that they hold the correct points.
I have tried to make it so my monsters turn to face their new destination smoothly (without just suddenly pointing at it) and then walk to it. But my monsters atm are just spinning around and around forever.
Im sure im simply doing something stupid, but I cant see it XD Can any of you see the problem?
case MON_STATUS_PATROL:
float turn = 1.1;
float move = 1.6;
if (DiffF(GetAngle(MonsterStack[n].dx, MonsterStack[n].dz, MonsterStack[n].x, MonsterStack[n].z), dbObjectAngleY(MonsterStack[n].eID)) > turn && !MonsterStack[n].daMet) {
MonsterStack[n].a = dbWrapValue(MonsterStack[n].a + 1.1);
dbYRotateObject(MonsterStack[n].eID, MonsterStack[n].a);
if (DiffF(GetAngle(MonsterStack[n].dx, MonsterStack[n].dz, MonsterStack[n].x, MonsterStack[n].z), dbObjectAngleY(MonsterStack[n].eID)) < turn) {
MonsterStack[n].a = Diff(GetAngle(MonsterStack[n].dx, MonsterStack[n].dz, MonsterStack[n].x, MonsterStack[n].z), dbObjectAngleY(MonsterStack[n].eID));
dbYRotateObject(MonsterStack[n].eID, MonsterStack[n].a);
}
} else {
MonsterStack[n].daMet = true;
//dbPointObject(MonsterStack[n].eID, MonsterStack[n].dx, MonsterStack[n].y, MonsterStack[n].dz);
MonsterStack[n].x = dbNewXValue(MonsterStack[n].x, MonsterStack[n].a, move);
MonsterStack[n].z = dbNewZValue(MonsterStack[n].z, MonsterStack[n].a, move);
dbPositionObject(MonsterStack[n].eID, MonsterStack[n].x, MonsterStack[n].y, MonsterStack[n].z);
}
if (DiffF(MonsterStack[n].x, MonsterStack[n].dx) <= move && Diff(MonsterStack[n].z, MonsterStack[n].dz) <= move) {
dbPositionObject(MonsterStack[n].eID, MonsterStack[n].dx, MonsterStack[n].y, MonsterStack[n].dz);
MonsterStack[n].dx = -1;
MonsterStack[n].Status = MON_STATUS_IDLE;
}
break;
GetAngle() obviously gets the angle between two points, Diff() is a function i wrote to return the differance between two values - DiffF() is the same thing but works on floats. Incase it helps, heres the code for those:
float GetAngle(float x0, float y0, float x1, float y1) {
x0 = x1 - x0;
y0 = y0 - y1;
if (!x0 && !y0)
return 0;
else
return dbAtanFull(y0, x0);
}
float DiffF(float a, float b) {
if (a > b)
return a - b;
if (b > a)
return b - a;
return 0.0;
}
[07:16:59-pm] « Sephnroth » you were dreaming about lee...
[07:17:13-pm] « Mouse » stfu

[07:17:22-pm] « Mouse » he was hanging himself lol