PDA

View Full Version : very very simple AI?



Bylkki
04-05-2003, 03:04 PM
First I just want say hello because I'm new to the forums.
Now the question. I'm making a FirsPersonShooter game and I want to have an enemy thats only trying to get to my position. So the enemy should have a path between its creation position and the player. There are no other objects blocking it so it doesn't have to go around anything just a straight line. How can I do that?
Sample code would be nice. :wink:
BTW I'm using glscene0.9 with delphi5.

Aeronautics
04-05-2003, 05:16 PM
You could determine the direction the enemy has to walk (in degrees, up is 0 degrees), and then using a certain step size to determine how many pixels the enemy has to go in the X and Y direction.

For example:




const
STEP_SIZE = 5;


procedure AI;
var
Angle: Single;
begin
Angle := Atan((PlayerY - EnemyY) / (PlayerX - EnemyX));

EnemyX := EnemyX + Cos(Angle) * STEP_SIZE;
EnemyY := EnemyY + Sin(Angle) * STEP_SIZE;
end;

Bylkki
04-05-2003, 06:58 PM
I couldn't get the example to work but I got the result with glscene's PointTo command like this

procedure TForm1.HandleAI(const deltaTime: Double);
begin
enemycube.PointTo(dummycube1, yhmgvector);
enemycube.move(cenemyspeed*deltatime);

It was that simple with glscene but thanks anyway for the example you gave me.