|
OK this is is kinda working the way I want it to. I place this as an Update Function in my Alien Zombie AI script:
My Alien Zombies are moving around my terrain a lot better and seem to be able to move around trees a lot better. But they pass through my buildings to get at my FPS player. The video tutorial I followed mentioned that the wall needed to have a box collider on it and I understand the reason for that. But is there a way to get this to work with my "Mesh Colliders" that are already assiged to each part of my buildings?? I would hate to have to go around and add an additional box collider to every part of every structure that they could possibly pass through ;) EDIT Morten Do you mean like this:
I'm going to go out on a limb and ask if the "Monster Size" determines if they can pass through a wall or not, is that correct? EDIT
here is an image of how things are set up and hopefully it demostrates what my Alien Zombies are doing wrong.
I added the debug code so I was much better able to adjust the parameters and center the sphere but as you can see they still just waltz right through my structures??
(comments are locked)
|
|
It's not easy to write a good AI code. But often a simple AI script is good enough as the one you have. I suggest one simple addition to your script: Only update the position to the new value if it doesn't collide with anything (Use Physics.CheckSphere(...) to check for a potential collision). In code it would be something like (sizeOfMonster and groundOffset should be replaced with variables for your game):
If you want more advanced AI you should take a look at Path or Behave ( http://angryant.com/ ). Or take a look at my blog about A* path finding ( http://blog.nobel-joergensen.com/2011/02/26/a-path-finding-algorithm-in-unity/ ). Edited 28th of May: To help debugging the size and position of the sphere use the following code snippet. This will draw the sphere-test collider in the scene when the GameObject is selected in the navigator: Thanks Morten, Where would i add this to my existing script? Oh I tried downloading angry ants package but it seemed to conflict with the detonator pack as I got an error message, can't remember what it was but when I unistalled it it went back to normal so I was unfortunately never able to test out the Angyant solution :(
Apr 27 '11 at 07:41 PM
Michael 12
My code snippet should replace the last line of your script (transform.position += ...).
Apr 27 '11 at 08:18 PM
Mortennobel
Thanks Mornet, I updated my Code in my question, does that look right. They still seem to pass through my game objects though, I did tinker with the monster size and it seemed like it had some effect??
Apr 27 '11 at 08:25 PM
Michael 12
What is the height of your monsters? Maybe the groundOffset needs to be different - like Vector3(0,0.5,0) or so. Basically what my addition to the script should do, is to make the moster stop, if it is about to collide with something. (Maybe you need to do something different - like change direction)
Apr 27 '11 at 08:52 PM
Mortennobel
The size of my Alien Zombies is 1.0 Wnat's the ground Offset and where would I change that?
Apr 27 '11 at 08:55 PM
Michael 12
(comments are locked)
|

