Morning all,
I was wondering if anyone knew of some advanced python scripting tutorials for the blender game engine. I want to script the AI for my game. I was wondering if blender had methods for figuring out the dot product and the cross product or in other words the distance from one object to another and the location of one object from another.
My goal is to make two bots.
Bot 1: Patrols till the player comes close enough, then persues, then when in range, shoot.
Bot2: Locates the closestā¦ lets say gold coin, moves toward the gold coin, picks up the gold coin, finds the next gold coin, repeat.
Any AI examples would be greatly appricated. Iāve searched the forums and google but havenāt found quite what I am looking for.
Thanks in advance,
delmarco
P.S. Anything I finish I will post back with comments to help the rest of the community!
I plan to write a continuation of my āBeginning BGE Pythonā tutorial, as soon as I find some free time. Seeing how AI is such a popular topic, Iāll probably base the tutorial around a simple enemy AI setup. Unlike my previous tutorial though, this one will be for people who have grasped the basic concept of the BGE API quite well. Meaning that just going through my first python tutorial wonāt be enough (I suggest taking some of my suggestions at the end of the current tutorial, and trying to add new functionality to that controll scheme example file).
The problem with this whole thing is not so much with the lack of documentation on the matter, as it is with the people who are looking for it. Usually these people are fresh green rookies with the BGE in general, yet all of them want somekind of a magical tutorial that can make them into programming experts overnight. Of course theese tutorials donāt exist, and I personally donāt think I could ever write such a tutorial even if I tried.
The point is: As with many other complex things, programming and game design are skills that usually require a few years to be learned properly.
My blender/python scripting skills are not the strongest. I think even more I need to brush up on my vector math skills. I also donāt know how to express exactly what I am looking for in a tutorial. After I finish the AI for this game (its due at the end of this month:eek:) I will post the .blend and maybe we can use it as one of those intro tutorials.
If you wouldnāt mind pointing me in the direction of some scripts that do implement some basic AI, it would be greatly appricated!
all that would be needed to do this should be a little 3d math, the scripting portion should be simple I believe.
basically having the gold coins in a list, get the position of the AI character, then doing the math of what distance it is to each of the gold coins in the array, keeping track of the shortest distance (should be simple geometry to get the distance if youāre only using 2 axis, 3d math needed if your X,Y, and Z are all used) then adding a trackto actuator
I havenāt looked at Socialās code so he might have a different/better way of doing it, Iām just explaining the concept of one solution.
1)Social,
That tutorial is amazing. I am going to spend the next few days implementing it in my game. I was thinking too low level and trying to do alot of the math myself. Can I help you in any way finishing the tutorial? I wouldnāt mind writing up the steps and getting play by play screen shots. Let me know what you think.
2)McAden,
I could swear I have the same write up as my solution for the project! Iām glad I am on the right track! I do have a request if youāre game:
Lets say I have N coins, thier object names are coin1, coin2, ā¦ ,coinN. Is it possible to have blender/python search the scene and return the # of coins. A better question would be how would I go about making that list of coins besides hard coding the amount in a for loop
list_Of_Coins
//is this the only way??
for (i=0, i< N,i++){
list_Of_Coins[i]= coin.append(i)
}
I donāt want to do it this way because:
Iād have to declare the number of coins before hand
Iād have to update this list during every pass (I may have to do this anyway)
Even if the coin is not in the scene anymore I would have to count it, or at least check for it.
You guys are thinking far too much in C. There is no need to do distance calculations.
Here, I made an example for the coin collector. (I think itās along the lines of what you asked for, you can modify it additionally if need be of course):
I simply used an 8 sided cylinder with a size (expansion) IPO to improvise a āsonarā. I kept the script very simple (again), so that you could get in the swing of things quickly.
When my IPO driven sonar hits the closest coin (by expanding), I use āgetHitObject().getPosition()ā to get the location of the coin. Then I set the Position of a āGuiding Emptyā (to which I have the collector tracking) to the same position of the hit coin, which gets the collector moving to the closest coin.
Simple.
Heh, I didnāt start it yet. The examples I gave you here are āquick and dirty thingsā. Actually Iām not even sure if my next tutorial should be on AI. Iām just brainstorming at this stage.
Iām āplanningā to write one, but itās hard to find the time to do it right. Anyone can put together examples, but good documentation is a whole other story.
Thank you for offering your help however. I appreciate it.
Social,
Great example! You are right once again I was thinking to low level. The BGE API is deeper then I thought. There is also a radar sensor, have you ever messed around with that?
My friend and I are finishing the soundwave game for a class. Iāll probably have another post by the end of this week. I will have to comment anything I do for class so by the end it should be a decent example.
I have an idea for a guided path. Put āmarkerā nodes along the path with thier own property. So the sonar not only returns the nearest coin but it also returns the cloest āmarkerā.
Yes, I pretty much messed around with everything at this point (Iāv been using blender for 2 yrs now).
The near, radar, and touch sensors have not been very stable for me in the past, so I try not to use them all that much (at least until the bugs get ironed out completelly). Actually, I donāt really need them, because I can always write a workaround with some other sensor, or just do everything with pure math (what you call ālow-levelā).
If your interested in learning more about logic bricks and how to use them visit the docs:
Itās the 2.43 parent bug thatās causing the problem. I made a quick workaround for it, and updated the original link, so just download the .blend again.
Heh, sorry, but thatās how blender works. Things that work fine in one version, may or may not work fine in the next. I wish there was something I could do about it.