Search Unity

Mecanim + "AI" [Free Sources]

Discussion in 'Made With Unity' started by Dkury, Jan 17, 2013.

  1. Dkury

    Dkury

    Joined:
    Jul 14, 2012
    Posts:
    46
    Play in Browser | Windows | Mac OS

    Source (works with Basic Version of Unity 4.2 and higher).









    Play in Browser | Windows | Mac OS

    Source (works with Basic Version of Unity 4.2 and higher).

    Howdy! I made a demo using a brand new animation system and great assets from a base Unity's Mecanim example scenes and a tutorial. My main goal was to understand Mecanim a little bit and made a demo using this technology. The overall experience was great and I am looking forward to work on other projects using Unity and Mecanim.

    In this demo you can find a robot guard: it can see you, hear you, search for you when lost from sight and even try to kill you. The robot's “AI” is a pretty simple state machine which behaviour looks surprisingly good with Mecanim and the navigation system.

    What do you think about Mecanim? Is it close to be like NaturalMotion’s Euphoria with later implementations from Unity Technology or external plugins? Or it was never supposed to be like that?

    ---

    Mecanim Example Scenes
    Mecanim Unity 4.0 starter tutorial
     
    Last edited: Jul 25, 2013
  2. Prion Games

    Prion Games

    Joined:
    Jul 1, 2011
    Posts:
    1,509
    Using this now, this could be of use to me, good job.
     
  3. SimonAlkemade

    SimonAlkemade

    Joined:
    Feb 4, 2009
    Posts:
    432
    How did you do the AI? I mean the casting of the sight?
     
  4. Dkury

    Dkury

    Joined:
    Jul 14, 2012
    Posts:
    46
    Hey man, you are welcome!

    Yeah, raycasting is an important part of a vision of the robot. Rays are tracing from its head in different directions, for example if it has 90° field of view, then it trace rays from 1° to 90° — 1 ray per degree or more (depends on needed quality of fow), and collect hit information from each ray. Then later in a script we can find if some of the rays hit the player.

     
    Last edited: Feb 8, 2013
  5. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    GitHub would be great, but posting it on Asset Store would be useful to I suppose.

    This looks like it would be useful for many people, myself included.

    What specific features of this require Pro? How easy would it be to port to Basic? I wouldn't imagine it would be too difficult, as the Pro features tend to be either graphics-related or advanced features.
     
    Last edited: Jan 17, 2013
  6. fano_linux

    fano_linux

    Joined:
    Jan 1, 2012
    Posts:
    909
    Awsome... i'll play with this... many thanks man
     
  7. Dkury

    Dkury

    Joined:
    Jul 14, 2012
    Posts:
    46
    It requires NavMesh which is using in a robot's navigation system. At first I was trying to implement A* but decided to stick with NavMesh — it was more interesting for me at first to make some sort of a game AI and implement animation. Yeah, maybe I will make it using A* later in order to fit Demo to Unity Basic.

    You are welcome!


    I found a bug in a webplayer version — sometimes after robot kill you and you appear on top of a container it seems like a collider became unactive at some point and the player just fall through the container. Weird.
     
    Last edited: Jan 18, 2013
  8. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    Please do. That would make this tool quite useful for basic users I think. I will certainly try your web player as well.
     
  9. Korda

    Korda

    Joined:
    Jan 3, 2013
    Posts:
    37
    Thanks for this Dima!
     
  10. Dkury

    Dkury

    Joined:
    Jul 14, 2012
    Posts:
    46
    You are welcome!

    I made a 2D field of view as an external package, if someone need it: look here.
     
  11. FlorianSchmoldt

    FlorianSchmoldt

    Joined:
    Jul 2, 2012
    Posts:
    334
    Fantastic job ! Thanks a lot

    I absolutly love mecanim. Blending animations, especially footsteps works perfectly. The only thing that bugs me, as a gfx only guy a bit, is that you still need some basic scripting skills to get simple keyboard inputs.
    The blending into states works pretty much as euphoria but I think one of their main feature is the possibilty to blend physics on top of every animation and let the character balance, protect himself or letting him reach for a discribed target ...or all at once.
    Mecanim is for sure a big step but something like Euphoria might be beyond Unitys capabilities and since they are paid by Rockstar, probably too expensive to get licensed.
    Would be great but I don't think, that's going to happen until Unity10, ...which will then be around 5.000$ : /
     
  12. Dkury

    Dkury

    Joined:
    Jul 14, 2012
    Posts:
    46
    Hey, man! Thank you for your response!

    I have not much of experience with animation (programming or actual animating) and may not be objective, but Mecanim seems as a helpful and powerful tool — from under the hood stuff to the user interface. All the blendings and state machine editing seems for me as native and easy to handle.

    I am a big fan of procedural approaches of managing content and believe that the future games will stand very close to smart-procedurally generated content.

    As you mentioned the NaturalMotion’s approach is much more than just blending animation into states. The whole concept is based on physical, neurological and even psychological simulations of bodies.

    There was an interesting presentation at Apple Event 12 on NaturalMotion’s upcoming title Clumsy Ninja. They make a real time simulation of a body, muscles and of essential nerves system at some precise and believable point on iOS devices.


    Impressive, right?

    As it was said by the guy from the presentation — this technology is based on many years of research at Oxford University. Who knows, maybe Unity would acquire some cool AI startup which works on this kind of stuff and integrate it with Mecanim. Or some genius would make it happen by making a $49.99 asset store plugin.

    But anyways, I hope that it would be accessible at some point soon for indie developers and would bring next-gen indie games experience to the players.
     
    Last edited: Feb 8, 2013
  13. Venged

    Venged

    Joined:
    Oct 24, 2010
    Posts:
    500
    Is there anyway I can make this work with the free version of unity? Is it just a matter of turning off light probes and pro image effects etc?

    Thanks,

    Robert
     
  14. Dkury

    Dkury

    Joined:
    Jul 14, 2012
    Posts:
    46
    Yes, you definitely could make it work on the free version. For now it is using NavMesh (Pro), but I guess it would not be a problem to replace it with some A* system.
     
  15. Jesse_Pixelsmith

    Jesse_Pixelsmith

    Joined:
    Nov 22, 2009
    Posts:
    296
    If you figure out how to replace with with Aron Granberg's A* Pathfinding Project that would rock! Been trying to get an AI system to work with Mecanim + A*
     
  16. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    Is it up for download?
    Is there any video tutorial for same?

    rahuxx
     
  17. petermicro

    petermicro

    Joined:
    Mar 13, 2013
    Posts:
    1
    Hi Thank you your Mecanim + "AI" [Free Sources].
    but I want to your web Player Version Scene.

    Robot AI and Boy Character Player is very nice Scene.
     
  18. mc13

    mc13

    Joined:
    May 23, 2013
    Posts:
    2
    where can i download this pls:)
     
  19. WJ

    WJ

    Joined:
    Oct 25, 2012
    Posts:
    97
    Would really like the source for this too :) I'm building a soccer game and I have the ai working with mecanim but the animations are glitchy. I'm not using Nav mesh because it's a mobile game but instead mostly moving from point a - b and rotating the rigid body, still would be good to see how you have implemented it.

    any tips on using mecanim for walk, run, attacks but rotating the rigid body so you can have instant rotation instead of the rotating in a wide circle type behaviour which doesn't work well for the crazy soccer type game I'm working on. Characters tend to slow down to rotate etc which isn't want I want and sometimes they even miss the ball because the rotation wasn't tight enough so I have to rotate the rigid body.

    Thanks
     
  20. GlorySimba

    GlorySimba

    Joined:
    Apr 18, 2013
    Posts:
    10
    hi dude, where can i download your source code?
    thanks a lot!
     
  21. Grespon

    Grespon

    Joined:
    Apr 13, 2012
    Posts:
    388
    Problems to run the WebDemo in Chrome and Firefox:
    "The content was stopped because a fatal content error has been detected"

    Just me ?
     
    Soumikbhat likes this.
  22. slkjdfv

    slkjdfv

    Joined:
    Oct 23, 2010
    Posts:
    435
    I got that as well in both Chrome and Firefox
     
  23. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,208
    Seems like a shockingly high number of raycasts. Perhaps consider inverting the logic, and only shoot rays at characters that are within the cone of sight, and see if they are occluded.
     
    Last edited: Jun 10, 2013
  24. Dkury

    Dkury

    Joined:
    Jul 14, 2012
    Posts:
    46
    Yeah, the last webplayer build was kind of broken on most platforms. Thank you for pointing out. I fixed it now.

    Actually Unity handles raycasting pretty well at least in this project. But I will agree that it wouldn't be wise to make such field of view visualisation method in an actual game. There are methods of finding out if someone is in a field of view without shooting hundreds of rays per physical step. And a visualisation of a field can be done by just a few raycasts and some smart shader, I guess.

    I think you have a nice point on optimisation of the current method and probably it can be applied to a more consumer end product. Thanks : )
     
    Last edited: Jul 25, 2013
  25. Kinos141

    Kinos141

    Joined:
    Jun 22, 2011
    Posts:
    969
    Good job, Respect.
    I think the player movement needs work, but overall, awesome!!
     
  26. Purpleshine84

    Purpleshine84

    Joined:
    Apr 8, 2013
    Posts:
    194
    Hi, looks very promising, but is this able for download? I mean: to use your code and animator/tree states etc. into Unity. In fact, I think you would make a lot of users very happy with that because there doesnt seem to be another example on the internet at all, and I searched a lot..
     
  27. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    722
  28. Dkury

    Dkury

    Joined:
    Jul 14, 2012
    Posts:
    46
    Hi Purpleshine84,

    Yeah, you can download and try it (526 mb) (let me know if the link doesn't work for you) on your Basic/Free Unity 4.2 and higher versions.

    I actually made this demo thing quite a while ago (January 2013) and it was working properly only on Pro features until recent 4.2 update when it became possible to use the NavMesh and dynamic shadows on Basic version, which is awesome.

    It's interesting that Unity website has this tutorial project now http://unity3d.com/learn/tutorials/projects/stealth which is pretty similar to what I was initially trying to do with Mecanim and Unity in order to understand this technology more.
     
    Last edited: Aug 13, 2013
  29. Purpleshine84

    Purpleshine84

    Joined:
    Apr 8, 2013
    Posts:
    194
    Great! Thank you so much!
     
  30. Mcg

    Mcg

    Joined:
    Mar 28, 2012
    Posts:
    112
    pretty sweet , should think of making a mobile optimized version im sure many people would be interested to buy :)
     
  31. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Great sample Dima

    Did you ever update the sample to just use Unity free?
    Downloaded and tried it, it went through an upgrade for Unity 4.3.4 But it broke the build, most scripts were no longer referenced and running the project highlights it still needs the NavMesh.

    Any ideas?
     
  32. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    Unity Indie/Free now (since 4.2 or something) supports Unitys built in pathfinding, although not all features. I believe this demo should run in Indie/Free.
     
  33. Pilltech101

    Pilltech101

    Joined:
    Jul 25, 2014
    Posts:
    35
    Is there a way to ad a melee Attack to this ?