Results 1 to 3 of 3

Thread: very very simple AI?

  1. #1

    very very simple AI?

    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.
    BTW I'm using glscene0.9 with delphi5.
    6872498642289459849826 flies can't be wrong... shit tastes good.
    <br />www.bylkkisoft.vze.com

  2. #2

    very very simple AI?

    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:



    [pascal]
    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;
    [/pascal]

  3. #3

    very very simple AI?

    I couldn't get the example to work but I got the result with glscene's PointTo command like this

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

    It was that simple with glscene but thanks anyway for the example you gave me.
    6872498642289459849826 flies can't be wrong... shit tastes good.
    <br />www.bylkkisoft.vze.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •