A.I 3d help
Blitz3D Forums/Blitz3D Beginners Area/A.I 3d help
| ||
Hi I'm trying to make some A.i for my third person shoot em up / beat em up but dont know how all i know is thta i'm suposed to use the const command in it and thats all please help me make cool A.I. |
| ||
A complete tutorial Mordy wrote for you ( well not you personally, but as good as ) : http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=morduun07112003153313.html |
| ||
Well That code is made for 2d so i will try to make it 3d but just in case is there a 3d A.I system anywhere? |
| ||
It's not that easy, your AI will need to fit for your game, so an AI that works for one game can make the peeps seem completely stupid in another. Of course you might just want the characters to attack on sight and otherwise do a predefined patrol route, but tell us. According to what you say it can really be a lot of different things you want. |
| ||
As EBusiness says, there is no such thing as one-size-fits-all AI. You learn the principles ( from reading Mordy's article ) and then you implement it. 2d and 3d is irrelevant in AI, as AI doesn't have anything to do with graphics. The graphics code comes before and after the AI, and is dependant entirely upon your game. |
| ||
Well i was going to if i got some 3d ai, edit it to suit my game because i dont have any idea on how to make ai for any 3d game. |
| ||
Ok, try making the opponents patrol. Then if the player is inside a certain radius, make them hunt him. You probably need something more advanced, but this will make something to build your AI on. |
| ||
What ebusiness said. Start out with letting the ai go from point a to b and work up from that. Once you get animation ect working you can work on effects like shooting ect. Add states to the ai and you have got a perfect ai for any game. Things to look into is waypoints, fuzzy logic and Finite states. |
| ||
Well i made a very simple A.I Using the entityvisible command so that if the enemy see's you then he/she will chase you, but i cant get it so that the enemy can only see in front of his/herself so that you can sneak behind him, any ideas on how to do that? |
| ||
Well, you must make a geometric model with some cone view area, let's see. Check the angle between the facing of the character and the line from the character to the player. There is probably some more or less easy Blitz way of doing that. |
| ||
http://www.gamedev.net/reference/articles/article1280.asp this article should help with figuring out if two things are pointing at eachother. a little complex, and I'm to tired to post an equation. |
| ||
Well could we try and make a realy good A.I system together for this type of game for everyones use and we can try and give pissific jobs to eachother on what to try and code. Cause this woul help me as well as others in the future who need help with A.I. |
| ||
This code will let you fustrum cull your looking entity's field of vision so that it only sees in front.TFormPoint EntityX# ( the_enemy_to_look_for_entity_handle ), EntityY# ( the_enemy_to_look_for_entity_handle ), EntityZ# ( the_enemy_to_look_for_entity_handle ), 0, your_looking_characters_entity_handle If Abs ( ATan2# ( TFormedX# (), TFormedZ# () ) ) < 40.0 Then If Abs ( ATan2# ( TFormedY# (), Sqr# ( ( TFormedX# () * TFormedX# () ) + ( TFormedZ# () * TFormedZ# () ) ) ) ) < 35.0 ;EntityVisible check goes here. EndIf It's also a good idea where you have multiple enemies looking out for each other to use EntityDistance to organize them into a near to far que so that you're checking the most likely targets first. Another thing you can do to speed things up is to limit the number of entities you are allowing to look around per frame and give them direct access to the positional information of the last enemy they sighted, between look arounds. I currently only allow one AI to look around per frame and I average about 2 EntityVisible calls per frame with a good reaction speed from the AI's with 30 of them running around in a small arena (at 80 frames per second). |
| ||
All good advice here. I mostly just want to elaborate on Axeman's last comment. Unless you need impossibly fast reaction times (and you probably don't since this would make your game too hard) there is no need for every enemy to be scanning for the player every frame. You might even want to stagger AI scans more than you have to in order to bring the AI's reaction time to something reasonable for the player. With 30 enemies that wouldn't be necessary but with only a few enemies that would be important. |
| ||
Sorry to be anoying but i dont understand the piece of code Axeman game me, cause i dont know what to do with it i.e where to put it how to put the pointentity into that code. |
| ||
Here's some more detailed code which should give you a clearer idea of how to use the earlier code I posted.; -- Set the 'current_enemy' variable to zero to indicate that no enemy is currently sighted by the bot. current_enemy = 0 ; -- Check if the player is within the bot's vision range (ie. If it's near enough to be seen). If EntityDistance# ( bot, player ) < bot_vision_range# ; -- Transform the player entity's coordinates from global space to local bot space for the viewing fustrum test. TFormPoint EntityX# ( player ), EntityY# ( player ), EntityZ# ( player ), 0, bot ; -- Check if the player is within the bot's viewing fustrum. If Abs ( ATan2# ( TFormedX# (), TFormedZ# () ) ) < 40.0 Then If Abs ( ATan2# ( TFormedY# (), Sqr# ( TFormedX# () * TFormedX# () + TFormedZ# () * TFormedZ# () ) ) ) < 35.0 ; -- The player is within the bot's viewing fustrum so check if it is visible to the bot. If EntityVisible ( bot, player ) ; -- The player is visible to the bot so load the players entity handle into the 'current_enemy' variable to indicate both that an enemy has been sighted and, also, which enemy has been sighted. current_enemy = player EndIf EndIf EndIf ; If 'current_enemy' variable holds a non-zero value, indicating that your bot has seen an enemy, then point your bot at the enemy and chase after it. Otherwise, rotate the bot to re-aquire the enemy. If current_enemy PointEntity bot, current_enemy MoveEntity bot, 0.0, 0.0, bot_move_speed# Else TurnEntity bot, 0.0, bot_guarding_mode_turn_speed#, 0.0, True EndIf Regarding that tip I gave you about giving your AI's access to the positional coordinates of the last enemy they sighted between look-arounds, you can also use this to simulate a highly efficient and convincing short term memory for the AI's. Just use a timeout to give the AI's access to the positional info of the enemy for a fraction of a second after they lose sight of it. You should loop through your AI's and delete the current enemy info of an enemy after it has been killed, though, or it will cause problems. To set up and use a timeout use this code: ; Note: You should assign the value of MilliSecs() to a variable at the start of your game loop and use that variable here in place of the 'MilliSecs()' function for maximum speed. ; -- Declare the timeout variables and constants. Const timeout_delay Global timeout ; -- Initialize the timeout. timeout = MilliSecs() + timeout_delay ; -- Check if the timeout variable has timed out. If MilliSecs() > timeout ; Timeout variable has timed out. Perform whatever actions you need to do here. EndIf |
| ||
Just a question is there any other way to do A.I? |
| ||
There are many ways to do AI but the easiest and most efficient way for computer games is the finite state machine aproach described in Mordun's tutorial. You could try doing some searches for AI on Google for info on other aproaches. I think there's some links to AI sites in the links section of http://wwww.blitzcoder.com/ too. Also, check out the new DeltaYaw and DeltaPitch Blitz commands for rotating your bot to face an enemy. |
| ||
Saddam. |
| ||
Well I had a look but did not find anything that helped me I now about the state machine A.I system and that is all but i dont know any other of how to use any A.I in blitz3d. |
| ||
If you look in the blitz3D forum for AI, there's some topics about AI there |
| ||
"Goober" - I'm assuming, by your return posts, that none of the above is really helping you: "all i know is thta i'm suposed to use the const command in it and thats all". Basically, "Const" won't be of much help with actual AI - I'm intrigued as to why you thought you needed it though. "is there a 3d A.I system anywhere?". Probably not a Blitz one that someone is going to just hand over - However, there is more than one type of "general" AI system - none of which may be suited to what you want to do. "Morduun" is right when he says "It's really easy, actually" - it is. However, you may have looked at "Finite State Machines: A Little AI Goes a Long Way" and thought "This doesn't help me as I don't know how to code it". What "Axeman" gave you may or may not be of use to you (assuming you understand it). "i dont have any idea on how to make ai for any 3d game". Which seems to be the key to your problem - you appear to want to do it from complete scratch (in terms of setting up variables to hold certain values to calculate other values to make your AI work). "Well could we try and make a realy good A.I system together for this type of game for everyones use...Cause this woul help me as well as others in the future who need help with A.I.". - "Goober", you hit the nail on the head: Check out "Blitz3D Beginners Tutorials by Ray Diaz" in the Tutorials section. This isn't specifically AI, but I think it's a good general tutorial. The Blitz community certainly does need an AI tutorial(s) in the "Tutorials" section regarding AI. The problem is there are so many uses of AI. What is required is basic stuff (initially), that is easy to understand, that builds up to be more and more complicated. It's too easy to tell someone to look for AI stuff in the forums or on the internet - the problem is some people (who are competant coders) won't need code, they just want to see how something is done (they know enough to implement an idea themselves) - whereas, some people are not going to get much help from this method (because they need to know how it all fits together - from scratch). Manipulating variables forms a base of AI (at least for me) - you need to be able to able to change/create values. AI can be "faked"/kludged to create whatever effect you want - you don't actually need an AI system as such - it's game dependent. "Kludge" your first stumbling block: You wanted to be able to sneak up behind your NPC - "Axeman" gave you some code, however, if you can't currently apply it to your code then kludge past this: You know what you want the AI to do (that fact that you cannot currently do it doesn't matter - pretend it does - you can solve this problem later) - you are using EntityVisible to check if the enemy spots you - "Goober" disable it at will with a key press, or by holding a key down. For example: hold down the left shift key to "sneak" and make your code disable the "EntityVisible" check while "sneaking" is on/activated. Technically, this means you could sneak up to the face of the enemy (which isn't believable). However, you can (at this stage of your program - in development) only press the button when you are approaching from behind the enemy (i.e. you are just "simulating" the sneaking which means you can carry on with your AI without stopping at this obstacle - by doing this you can carry on developing your AI (coz you still have to work out what happens when you sneak up on the enemy - as the distance shortens from you to NPC you could increase the chance of the AI "detecting" you (perhaps it can hear you). From a basic AI point of view - set up some base variables (stats) in your code: you can set one up for the distance the AI can hear you (this is somewhat unreal as hearing also depends on volume, etc. - but don't worry about this yet) - once the distance between entities gets within this value you can start throwing a random number which decreases in randomness as you get closer and closer (but not to low that it means you'll never successfully sneak up to your target). Looking at "Morduun's" "Finite State Machines: A Little AI Goes a Long Way" SEARCH: You'll probably use the idea of this FIGHT: You'll probably use the idea of this PANIC: You'll probably use the idea of this REST: You'll probably use the idea of this SUPPORT: You'll probably use the idea of this - if you have more than one AI enemy SNACK: Possibly - The AI in Gothic 1 and 2 enabled NPC's to eat to heal themselves slightly SPAWN: Probably not "States" can include anything you like - sleeping - poisoned - bursting to go toilet. If you have used "EntityVisble" then you can certainly make use of Fight. If you have more than one enemy, you can give then varying levels of "Courage" (as a base variable) - you can experiment with some NPCs just running away (maybe to raise the alarm or to hide), yet some who just come straight after you. Give them various levels of health/ammo, etc. - then you'll start seeing your AI "work" (without doing much AI stuff). Give them moods (a value of 1 could be happy/0 angry/2 worried/3 scared, etc. etc.) - once you change values you have to work out how it affects the "AI" of your NPC. A NPC of low "courage", that's injured and just run out of ammo is likely to run off. If it had ammo it may still run off rather than reload (perhaps to heal itself - it would be pretty stupid AI to just stand there and heal itself while you are blasting away at it - funnily enough, a lot of commercial game AI does just this). Don't worry to much about doing an AI engine - for now just play around with variables. In a nutshell, you can create more complex AI in your Blitz game (purely with playing with simple variables) than you'll find in many commercial games that have specific AI engines - there are drawbacks though. I was thinking about sticking my neck out and doing an AI tutorial (for the tutorials section) sometime in the new year - with the aim of it being really, really simply written (designed for a programming novice, not just an AI novice) - we'll see. |