# adding people to a game?

This topic is 3875 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, I'm making a First Person Shooter as a "learn as you go" type of thing. I was wondering, how do I add monsters/people/etc into the game? Would I code each monster with its position into the game, or would I use a level editor to add them. considering that there are going to be a lot of monsters, I figured that there was a way to do it using some level editor. If I do use a level editor to do that, what is a good one that I can use and easily load it into the game with the Irrlicht Engine? Before I was using 3d world studio, and before that gtkRadiant. I didn't really like gtkradiant because your sort of restricted with the games that it was originally made for. I seemed to get along with 3d world studio alright, but I wasn't sure if it had the capabilities I need to add people into the game. Thanks. All help is greatly appreciated.

##### Share on other sites
3D world studio does support entities, even lets you create your own classes of entities, its probably the best level editor I've tried, the downside is that it's not free and has a single author, Josh, who well... lets say doesn't pay that much attention to his customers suggestions and bug reports.Also I think he was going to raise the price way high for the 6.0 version... I should check the site and see what happened, I am supposed to be able to get it for less if its out since I own 5.x.

You can also look for free (as in beer) alternatives like Hammer (link) or Torque Constructor (link).

You already know of the free (as in speech) gtkRadiant, and then there is QuArK (link).

Just one last thing, editors don't just magically create the "people" into the level, what they do is save information about entities (like position, model file to use, texture file, etc), how you handle that information inside your engine is up to you.

##### Share on other sites
Oh thank you a lot. I really appreciate it. So I basically have it like this, lets say for my monsters. I have 10 different types of monsters (each with its own class), each derived from a monster base class. I can use 3d World Studio to position my monsters and there textures etc, then I would code in there behaviors.

This is going to be off topic but I was wondering what the best way to code simple AI behaviors would be. Should I just use a bunch of if statements to check if certain things are true then have have my monsters play a set animation frame and do the behavior for each if? Like: If monster position is within 20 feet of player position == true AND visible to player == true then charge at player.

Thanks again.

p.s. I'm using C++

##### Share on other sites
Quote:
 Original post by cemediasThis is going to be off topic but I was wondering what the best way to code simple AI behaviors would be. Should I just use a bunch of if statements to check if certain things are true then have have my monsters play a set animation frame and do the behavior for each if? Like: If monster position is within 20 feet of player position == true AND visible to player == true then charge at player.

Quick comment. It looks like you're writing things like that because you're under the impression that you would have to include the "== true" in actual source code. This is not the case, and in fact it is a bad idea to do so: it is extra typing with no meaning. It adds a place where you could make a mistake (such as putting "= true" instead), and makes things less clear.

In real life, you would say "if the monster's position is within 20 feet of the player". You would not say "if it is true that the monster's position is within 20 feet of the player". Code should be treated similarly.

##### Share on other sites
Quote:
 Original post by cemediasThis is going to be off topic but I was wondering what the best way to code simple AI behaviors would be. Should I just use a bunch of if statements to check if certain things are true then have have my monsters play a set animation frame and do the behavior for each if? Like: If monster position is within 20 feet of player position == true AND visible to player == true then charge at player.Thanks again.p.s. I'm using C++

Zahlman is right, use if(visible) or if(!visible) rather than if(visible==true) and if(visible==false) where possible.

That said, yes, but its a bit more complex than that, you should use states (IE: idle, running, walking, eating, chase, flee, etc) but you have to set those states with if statements based on the variables you mentioned.

##### Share on other sites
Thanks. I've never made a game this complex before so I wasn't sure how to do this. I have a few more questions. First, how do I access the classes I implement into my level using 3d world studio? Will I be able to use them automatically after I load the level into memory? And second, I've never coded AI before, so I was wondering how it would be best to organize the code. If anyone knows of any tutorials that would help, that would be greatly appreciated. I don't want to do anything too complex, I just want the basic actions as stated: like if the player comes close to an enemy, the enemy will attack. Things like that. I've searched for AI tutorials on the net but they all seem very complex.

Thanks again.

P.S: That was the impression that I was under. I know that I'm capable of making this game, I've already made a demo that uses most of the features I want in my game. The only thing I'm really having trouble with is the AI. I don't want my game to become a failure just because I can't program the AI. Like I said in my first post, I'm trying to use this project to further my knowledge.

EDIT: Would it be a good idea to start a new thread and ask these questions?

[Edited by - cemedias on July 11, 2007 11:00:42 PM]

##### Share on other sites
Quote:
 Original post by cemediasThanks. I've never made a game this complex before so I wasn't sure how to do this. I have a few more questions. First, how do I access the classes I implement into my level using 3d world studio? Will I be able to use them automatically after I load the level into memory?

Well, you have to write level loading code into your engine, I have no idea what format you're using for your levels, but regardless of which one you use, it is all really up to you, the level file contains data, how you process that data is your responsibility.

For example lets say you have an entity which is meany1 an entity of class meany, it is located at position x,y,z, uses model meany.obj and texture meany.png (I wont add rotation information not to make it any more complex).

That information is in the level file, on your loader code, you should know first that the information belongs to a meany, that its name is meany1, and that you should set your transformation so a polygon mesh loaded from meany.obj and textured with meany.png shows in position x,y,z.

Since a meany is something thats not static, that would be the "start" position, and the loader should also add things like initial HP, and state (IE:idle or patrol), from then on, the AI takes over.

but all this is stuff YOU have to program, unless you're using something like 3d game studio, Torque, some other premade engine, or moding an existing game like Half Life 2, Doom 3 or Quake, you have to code it yourself. There is no built in CreateMonster() in C++.

That said, once you get the values from the level editor, you could have a class like:

class meany{public:meany(float* position,float* rotation,float* scale,std::string& model,std::string& texture){}}

and then do new meany([values read from level go here]), but you still have to fill that constructor and all the other methods a meany entity will need.

If you're going to use the 3dws file format for your levels, the specification is on the help file... what are you using by the way? X files and Direct3D? I am not sure if entities get exported or how to X files.

Quote:
 Original post by cemediasAnd second, I've never coded AI before, so I was wondering how it would be best to organize the code. If anyone knows of any tutorials that would help, that would be greatly appreciated. I don't want to do anything too complex, I just want the basic actions as stated: like if the player comes close to an enemy, the enemy will attack. Things like that. I've searched for AI tutorials on the net but they all seem very complex.Thanks again.

I'd use a state variable and a state function, something like:

enum States{IDLE=0,PATROL,SEARCHING,FIRE};class entity{public:entity(){state=IDLE;};void DoAI(){switch(state){case IDLE:DoIdle();break;case PATROL:DoPatrol();break;case SEARCHING:DoSearch();break;case FIRE:DoFire();break;}}protected:States state;virtual void DoIdle();virtual void DoPatrol();virtual void DoSearch();virtual void DoFire();}

of course state changes inside of the functions, for example DoIdle would check for nearby enemies each time and if there are any in close range, it would switch to fire (which may require a target), or maybe if it stays idle for too long, it may switch to patrol, or if firing and the target gets out of range, switch to search, etc.

Quote:
 Original post by cemediasP.S: That was the impression that I was under. I know that I'm capable of making this game, I've already made a demo that uses most of the features I want in my game. The only thing I'm really having trouble with is the AI. I don't want my game to become a failure just because I can't program the AI. Like I said in my first post, I'm trying to use this project to further my knowledge.EDIT: Would it be a good idea to start a new thread and ask these questions?

I think you're overestimating the simplicity of a FPS, I am not saying its impossible for one person to write one, but its not the same as codding pong or tetris.

If you have a new question, hopefully a little more detailed, then start a new thread, if the question is a follow up to the original topic title, then don't.

##### Share on other sites
Thanks for the reply, it really has helped. I appreciate it.

Well, I'm using the Irrlicht Engine for my game, and as of now I'll be loading my entities as .x files.

I guess technically I haven't been making the actual game yet. Right now I've been working on making a tech-demo to test all of the features in the engine and everything that I want to be in the game, in a small level I've been designing. It has been difficult doing all of the graphics design and programming for the game by myself, but I guess it's my only choice. Nobody that lives anywhere near me is as computer literate as I am (gift and a curse hehe). I'm loading my levels as .b3d files also.

The Irrlicht Engine has a function to load my models with the format that I'm using, but I don't believe the loader can do some of the things you stated, like the HP and state. I guess I will have to write my own loader function.

Thanks to you, I now understand what I need to do with my States for my AI. I can't express how much I appreciate it. I'm still a little iffy on how I'm going to write my level loader code. So from what I understand my level loader should handle the classes that I use for my entities, right?

I think I understand this a lot better now. Still, if anyone has any tips on level loader code, that would be helpful. Another thing, is the .x file a good format to use to load my entities with? And b3d for my levels? I suppose that since I'm going to need to write my own level loader I could just use the .3dws format, considering that it's documented and I wont lose any information that I originally put into the level in the editor. I was just using b3d because it was the only format that my engine loaded that supported the lightmaps.

Any more tips or ideas would be helpful. Thanks again!

##### Share on other sites
I made a new thread to discuss this: "making my own level loader, tips?"