It’s good to see Python AI tutorials. The old Logic Brick one is nice but it’s a bit arduous for the result. My only suggestion is that you swap out the d-loc for a servo actuator. It will give nicer collisions should something without the “wall” property get in the way.
Oh and here’s the file, notice how he doesn’t go into the cells because he doesn’t know they exist! he only sees the walls infront of him. This is what tutorial 2 will cover, making him have peripheral vision. If you want to follow tutorial 2 with this file be my guest, it will increase simplicity and make you understand better. If you followed the tutorial right it should be exactly the same, just with a different maze.
Ok, you caught me! but I was really just talking about further down the line when you make it more complex.
I was about to write about the weird bouncing etc you can get with d-loc some more and decided to whip up an example. That said, when I tried one using d-loc and one with a servo they both slid at a curved corner where there was collision but no ray intercept.
My apologies good sir, I was very wrong!
[What I was about to say]
I noticed that when the guard turns it’s not exactly 90 deg. So if you have a level with more complex geometry and a bunch of random props the guard may clip the edge. With d-loc and dynamic objects you tend to get weird bounce back but if he clips the edge with lin-v instead he will just slide arround.
what would be cool would be to use the getHitNormal of the ray and turn that 90 degree in a random direction. That way you can have AI follow diagonal walls too. The tricky part is that getHitNormal returns a vector and setOrientation requires a matrix so there is some conversion needed.
I’d say it’s do-able. I’ve never looked at the orientation matrix before but I have done some study of matrices in college. A vector is basically a small matrix and there are a tonne of mathematical methods for inter-converting and adding and subtracting values.
If the matrix works the way I would assume it does then to do this you would be required to find the object’s orientation and replace the z-values with those obtained from the getHitNormal command.
I have to say that’s a great idea and is far more accurate than the turning method.
As a python n00b I’m glad these tutorials are being made. I’ve dabbled before but a whitespace language that you don’t compile confuses the hell out of me. I’m learning a lot from these already!
By the way, logic bricks are written in C++ and are therefore more computationally efficient than python (python is written in C, so you are going a few extra steps than you should have to). They may be inefficient to create, organise and control but they don’t slow down computers as fast as the equivalent in python (most of the time). Although you do have more flexibility with python so you may not need as much logic to do the same thing… Anyway, there are advantages and disadvantages but the statement
BRICKS SLOW YOUR COMPUTER!!
is not automatically true.
It’s possible to not use the ray sensors and collisions to move an object around, you can use pathfinding.
I posted a thread with some links to help people create pathfinding: http://blenderartists.org/forum/showthread.php?t=142297
I’ve successfully made pathfinding twice, once in 3D and the other using tile based terrain. With out too much fret it would be possible for you to choose a random location and plug that into a pathfinding script to produce your random movement. Allthough you might have to use your ray sensors to dodge other moving objects.
You should try to implement some pathfinding as its fundamental to AI, because your AI’s not going to look very smart when it walks head on into walls.
It’s defiantly doable, no question about it. I’ve read some vector and matrices maths, it’s not that hard once you understand how to think. Social wrote an excellent tutorial on the orientation matrix. The matrix works by organizing the x,y,z point to which and each axis is pointing in local space, I guess (will sturdy it more) that the vector outputs three angles, for x,y,z. If so, then it shouldn’t be harder than to add/subtract 90 degrees on the z-axis, convert each angel to the base circle and put the coordinates in the matrix.
I’m glad you all enjoy! I plan to touch bases with matrices whenever I get around to the more advanced section. This next part is really long and I’m going to be really busy, but I plan to release it in the next 2 days!