AI - to get start

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
804
Posts: 73
Joined: Thu Nov 10, 2011 7:07 pm

AI - to get start

Post by 804 »

I want to develop a simple AI for a robot like this:
Image
Please give me a hint where i should start!
The main point the AI should support waypoints (first without any collysion).

Now my questions:
1. How can I programm a function like this:

Code: Select all

enemynode->moveto(core::vector3Df endpos);
2. I don't know how to check if the enemy can see the player.
3. How to make the robot looking at the player (rotation).

PS: Please don't post any links to AI plugins (i want to programm it myself).
///////////////////////////////////////////
My Forum: http://game-home.1x.de/
My Homepage: http://mediadesign.about.lc/
///////////////////////////////////////////
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: AI - to get start

Post by Cube_ »

search the forums for a program called IrrAI

It is in the Project Announcements board. more exactly here: http://irrlicht.sourceforge.net/forum/v ... hp?t=25132
"this is not the bottleneck you are looking for"
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Re: AI - to get start

Post by Katsankat »

Looks like your project is very photorealistic, well done.

It is very simple actually.

First off I made it by embeding an interpreter to test AI scripts without having to recompile the whole program.
http://irrlichtirc.g0dsoft.com/kat104/3D/img/irr14.png
It is a LVTP turret because I'm not a good modeler. Anyway

The robot (or human/boat/helicopter/whatever) has simple functions:
goForward();
goTurnLeft();
goTurnRight();
isInPosition(); <- returns true when he has reached a waypoint, there increment index of waypoints when true
You know he is in position with a simple calculation: when abs(pos.X - waypoint.X) < 100.f && same for Z

In the main loop the bot is thinking
while(!isInPosition()) { Do I go left or right? forward();}

All these functions were posted in the forum by Rogerborg or someone cool like him ...
That's all.

We'll discuss about people seing each other or not, later when movement is done. It is a simple question of boxes intersecting eachother or not and raycasting to check if there is a wall inbetween.
804
Posts: 73
Joined: Thu Nov 10, 2011 7:07 pm

Re: AI - to get start

Post by 804 »

Thanks for these hints :D
I will Read through the Posted links, start my project and post more questions.

Ps: the Photo above isn't ingame, its just a Photo i Found in the i nternet, because i was too Lazy to upload a real screanshot.
Here is a screenshot of another game that uses the same robot as i use.
Image
It is out of this serious moddel pack: http://www.thegamecreators.com/?m=view_product&id=2287
///////////////////////////////////////////
My Forum: http://game-home.1x.de/
My Homepage: http://mediadesign.about.lc/
///////////////////////////////////////////
804
Posts: 73
Joined: Thu Nov 10, 2011 7:07 pm

Re: AI - to get start

Post by 804 »

I started programming the basics of the AI, but want to know what you think about these few lines of code:

Code: Select all

#pragma once
 
#include "enemy.h"
#include "main.h"
#include <vector>
#include <irrlicht.h>
using namespace irr;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
namespace AI{
        class waypoint{
          public:
                core::vector3df pos;
                bool active;
 
                waypoint(core::vector3df _pos, bool _active){ pos = _pos; active = _active; }
                waypoint(){ active = false;}
                void setup(core::vector3df _pos, bool _active){
                        pos = _pos;
                        active = _active;
                }
        };
        class way{
          protected: 
                  int amount_active;
                  std::vector<waypoint> waypoints;
          public:
                way(){amount_active = 0;}
                void addWP(std::vector<waypoint> _waypoints){
                        for(unsigned int i = 0; i <= waypoints.size(); i++){
                                waypoints.push_back(_waypoints[i]);
                        }
                }
                void addWP(core::vector3df _waypointpos, bool _active){
                        waypoint tmp(_waypointpos, _active);
                        waypoints.push_back(tmp);
                        if(_active) amount_active++;
                }
                void addactiveWP(core::vector3df _waypointpos){
                        waypoint tmp(_waypointpos, true);
                        waypoints.push_back(tmp);
                        amount_active++;
                }
                void addinactiveWP(core::vector3df _waypointpos){
                        waypoint tmp(_waypointpos, false);
                        waypoints.push_back(tmp);
                }
                void setWPactive(int iID, bool _active){
                        if(_active && ! waypoints[iID].active) amount_active++;
                        else if( !_active && waypoints[iID].active) amount_active--;
                        waypoints[iID].active = _active;
                }
                int getWPamount(){
                        return waypoints.size();
                }
                int getactiveWPamount(){
                        return  amount_active;
                }
                int getinactiveWPamount(){
                        return waypoints.size() - amount_active;
                }
                bool getwaypointactive(int iID){
                        return waypoints[iID].active;
                }
                core::vector3df getwaypointposition(int iID){
                        return waypoints[iID].pos;
                }
                waypoint getWP(int iID){
                        return waypoints[iID];
                }
        };
};
namespace enemy{
        scene::IMesh* robot_01;
        void load(){
                robot_01 = smgr->getMesh("data\\enemy\\model\\robot_01.X");
        }
 
        class main{
          protected:
                int lastWP_id;
                int nextWP_id;
          public:
                AI::way way();
                main(){}
                main(AI::way _way){ way() = _way;}
 
                void calcnextWP(){
                        if(nextWP_id == lastWP_id){
                                if(lastWP_id != way().getactiveWPamount()){
                                        do{
                                                nextWP_id++;
                                        }while( !way().getwaypointactive(nextWP_id) );
                                }
                                else{
                                        nextWP_id = 0;
                                        if(!way().getwaypointactive(nextWP_id)){
                                                do{
                                                        nextWP_id++;
                                                }while( !way().getwaypointactive(nextWP_id) );
                                        }
                                }
                        }
                }
                void setWay(AI::way _way){ way() = _way;}
                AI::waypoint getnextWP(){
                        if(lastWP_id != nextWP_id) return way().getWP(nextWP_id);
                        else{
                                calcnextWP();
                                return way().getWP(nextWP_id);
                        }
                }
        };
        class robot : main{
          private:
                bool patrol;
                int reachedWP;
          public:
                void setup(){
 
                }
                void movetonextWP(){
 
                }
                void moveto(core::vector3df _pos){
 
                }
                void stop(){
 
                }
                void turn(short angle){
 
                }
                void moveforward(int speed){
 
                }
                void moveback(int speed){
 
                }
                void lookaround(){
 
                }
                void lookat(core::vector3df _pos){
 
                }
                void search(){
 
                }
                void die(){
 
                }
 
        };
};
The whole stuff will be rendered by one function (but so far i just wrote some basic stuff).
///////////////////////////////////////////
My Forum: http://game-home.1x.de/
My Homepage: http://mediadesign.about.lc/
///////////////////////////////////////////
Post Reply