SecretAsianMan

Unity Tutorials

Recommended Posts

I am about to start down this terrible path of learning Unity with only a bit of basic coding experience. It is my honest intention to document and blog both my learning process and the results as they develop. I have the game concept, and i have the tools... All I need now is some spare time.

I will enjoy reading it. ...assuming you post about it on the forums.

Share this post


Link to post
Share on other sites

Unity cookie has a pretty good intro tutorial series. Its pretty light on more complex stuff though, although there is a shader series thats very in depth.

 

The shader tutorial is an absolute must watch if you ever plan on making your own shaders.  It dives in pretty deep, but is great to understand that you could be killing your performance on a certain device just because you chose or wrote a shader that is not optimized for that platform.

Share this post


Link to post
Share on other sites

Has anyone any experience on making AI in unity/ue4? It's always there in the back of my mind, I generally have game ideas with NPC's in them. Is it feasible for an artist with some coding skills to do AI? It seems like a big undertaking and steep learning curve. Would you just get a real programmer? What do you guys think?

Share this post


Link to post
Share on other sites

I'm experienced with AI, if you could give some more details on the mechanics of the game, or what behaviors the AI will need I can give you a better answer of what might be involved.

Share this post


Link to post
Share on other sites

For the purpose of discussion, what about the AI in a game like Thief or Dishonored?

Share this post


Link to post
Share on other sites

The tornado twins worm game tutorial isn't a bad one to start with:

 

Don't worry that it's an older version of Unity. Also if something's not working for you, try going on to next tutorial, as they often address the bugs of the previous one.

Share this post


Link to post
Share on other sites

For what it's worth I haven't done that type of AI before, but I can give you a general look at what an AI for an NPC in a 3D stealth game might entail.

 

The gist of it is that the character would have a set of behaviours and a set of inputs that change which behaviour is playing. Let's look at a "guard" character. The guard is patrolling his footpath. The player character makes a loud noise, the guard hears it and starts walking towards the source of sound. The guard sees the player character and starts shooting at the player character. The player character drops a smoke bomb and the guard starts searching for the player character. You're probably already picking out the different Inputs and Behaviours, but let me go through them in some more detail and highlight the problems to solve for this AI.

 

The guard is patrolling his footpath. You set up a path in the design of the level as this characters patrol path. You make the guard navigate waypoint to waypoint as part of his patrol behaviour. Maybe you add some code to tell him to wait at a way point for a few seconds. Maybe that amount of time is randomized to make him appear a bit more human.

 

The player character makes a loud noise. When you have this "loud sound" event you check in a spherical radius around its origin to see if there are any guards. Does the world geometry block this sound? Does the magnitude of distance from the sound matter? Does the kind of sound it is matter? 

 

The guard hears it and starts walking towards the source of sound. Now our guard has to navigate a 3D space. One way to do this is to have a set of waypoints all over the stage that NPCs use to navigate. If you have this, the guard will have to do pathfinding across this graph of waypoints. 

 

The guard sees the player character and starts shooting at the player character.The guard has some sort of vision. World Geometry should block this. How far and wide can the guard see? Is the player character the only thing it will react to seeing? How good a shot is this guy?

 

The player character drops a smoke bomb and the guard starts searching for the player character. Does our guard have a special reaction to a smoke bomb? What is the method for searching? How long does the guard search for?

 

Hopefully this illustrates the idea that a fairly basic interaction for the stealth game can have a lot of different things involved with the AI. There's a good chance the engine you use has an in-built solution or plug-in to handle the technical details. As a designer you're then looking to design the behaviours and inputs in a way that makes the NPCs look "human" and still remains balanced with the gameplay. 

 

A stealth game is probably one of the extremes of AI design. You could perhaps imagine a game where the only AI behaviours are patrol and shoot. Additionally, AI for a turn based game like chess would be implemented in a very different method than described above, and if you want insight on that I can provide. I hope this sheds some light on what you're trying to achieve.

Share this post


Link to post
Share on other sites

Alright wow, so in the last couple of days, looking at this, I think I get it now. I had vaguely heard about event handlers and state machines before, but now it all clicks.

Actually, after I posted yesterday I watched the AI chapter in unity's stealth project. Today I also watched the State machine tutorials for Playmaker, I don't have playmaker, but even then it helped. Thanks for the help, I feel kinda silly now. Though one takeaway is also I'm amazed at how much Unity has out of the box. Ugh, alright then.

 

Beginner Stealth : Chapter 4

 

 

Edit: This forum is very nice place, thanks again!

Share this post


Link to post
Share on other sites

Given the amount of interest I've seen in State Machines and AI here, would anyone be interested if I made a small example of these at the intermediate level?  It seems like there are a number of examples to go over the basics but from what I can find little beyond that.  Basically I'd go through the planning and implementation of a particular element of AI design such as sensing the world or take a bit more of an in depth look at state machines.

Share this post


Link to post
Share on other sites

itsamoose, I think I can safely speak for everyone when I say, that would be amazing and greatly appreciated.

 

To add to this whole AI thing, it's really easy to make things/NPCs/whatever you can dream of, move around in unity.

Just watch this super short series on nav-mesh baking and nav-agents: Unity > Tutorials > Navigation.

 

Maybe there should be another discussion thread about AI, I didn't mean to hijack this thread..

 

EDIT: The AI discussion has graduated to get its own thread here, yay!

Share this post


Link to post
Share on other sites

For the purpose of discussion, what about the AI in a game like Thief or Dishonored?

Are you aware of the stealth game tutorial project on Unity's site? I haven't tried it myself, I never actually finsihed the space-shooter one, but I imagine that this might be something that would help you out.

http://unity3d.com/l...rojects/stealth

Share this post


Link to post
Share on other sites

I decided to start with the Space Shooter tutorial. I've now been trying to adapt the little bit I got from that into creating a space shooter of my own that has all the trimmings like bosses, multiple stages, etc. but using 2D instead of 3D.

 

It's been pretty enlightening so far. I decided to work exclusively in C# since I don't know anything about C#.

 

First thing I did was spawn a random set of stars at random move speeds to give the illusion of depth in the star field. Now I have a player ship that shoots, a single enemy that comes down in 3 different movement styles (simple sine wave, stepped straight path, and straight at the player), and they shoot as well. The difficulty increases in 30 second increments by increasing enemy speed and enemy fire frequency. And every enemy that gets past you does damage to the Earth in 5% increments, with a game over screen when the planet dies.

 

I want to figure out the 2D animator next. The player ship (which is totally just an F14 Tomcat) should launch into the screen on a new life, then have the wings move out to the ready position as it settles into the player's origin position.

 

After that I will probably work out a couple more enemy types so it's not just one purple circle moving in 3 different patterns, and maybe the first mini-boss. If I go as far as the mini-boss I will also want to do some basic power-ups.  That's more just putting in the hours, though. I think I know how to make them all work.

 

I also need to figure out an art style and do some permanent art assets, but that will be nearer to the end of the gameplay loop being finished.

 

I've been blogging a little bit about it, though I think it might be more interesting to talk specifics about the code and how it relates to the gameplay. I'll tackle that in my next post this weekend, I think.

Share this post


Link to post
Share on other sites

I might end up buying this extension. It looks like a way I could add a lot of animations easily. Part of me wonders if these 2d tools already exist in mecanim or something and I'm just not aware of it yet.

 

 

Nevermind, looking into it a bit, it looks like Unity already does this stuff.

Share this post


Link to post
Share on other sites

I'm starting to experiment with making physicalish machines in Unity. It doesn't work all that great. When I have one object on a hinge-joint attached to one other object, everything is fine. But if I have any cascading of hinge-jointed objects (especially with motors), it doesn't take long for all the pieces to start drifting, clipping, and jumbling.

It occurs to me that there might be a tutorial series on this type of thing. I'm going to keep experimenting, but I thought y'all might know of a tutorial that would give me some pointers on how not to break Unity's physics simulation capabilities. My goal here is basically to create objects of multiple parts (all with their own mesh-colliders) that perform somewhat realistic mechanizations. I suspect that the 2d physics does this far more reliably, but I'm not ready to give up on getting something out of the 3d physics stuff.

Share this post


Link to post
Share on other sites

You could try making animations with the 3D objects and turning on Animate Physics to get something that feels similar.  For the most part I don't think making physics machines in 3D works very well, where in 3D you have 3 position dimensions, and 3 axes of rotation, whereas 2D only has 2 position dimensions and 1 axis of rotation.  Ultimately there is just a lot more that can go wrong with 3D physics-based walkers or other machines not to mention the performance impact.  You could also try faking it with wheel colliders that are just kind of at the bottom of the object, or check this out to see if it has what you are looking for.  Also you might want to look into Physics materials if you aren't using them already to help achieve the effect you're looking for.

Share this post


Link to post
Share on other sites

I've been going back and forth and the three methods to move things around the screen in my 2d shmup.

 

I could hand-animate every ship's path through the play area, but then I either have to do a ton of them and then I still limit the variation possible.

 

I could move them mathematically, as in make is so X=Sin(Y) with a constant increase to Y, but that's difficult to get complex paths working, and when you only update Y every frame update, you can get screwy results when you increase your speed.

 

Or I could use the physics engine and apply forces to the enemy ships to move them. I'd be into new territory on that, though, so I'm not sure what issues could crop up.

Share this post


Link to post
Share on other sites

Learning how to use the physics engine to move stuff isn't all that difficult, but just a warning: Box2D is deterministic, but only on a per-hardware basis. There's no guarantee the movements will be the same across different machines. This largely only shows itself in floating point errors, so in most cases it's so small that it's not noticeable, but it's worth keeping in mind if you're doing anything super complex. With lots of object interaction.

 

For pure movement, if the ships/whatevers won't actually collide with anything besides the player ship and bullets, it's probably fine.

 

Also for purposes of moving ships around in a shmup, I personally probably wouldn't touch forces. I'd just straight set the velocity and let it go, or change it based on what kind of pattern you want.

Share this post


Link to post
Share on other sites

You could try making animations with the 3D objects and turning on Animate Physics to get something that feels similar.  

 

I didn't think of this. I'm going to try that out.

 

I've been going back and forth and the three methods to move things around the screen in my 2d shmup.

 

I could hand-animate every ship's path through the play area, but then I either have to do a ton of them and then I still limit the variation possible.

 

I could move them mathematically, as in make is so X=Sin(Y) with a constant increase to Y, but that's difficult to get complex paths working, and when you only update Y every frame update, you can get screwy results when you increase your speed.

 

Or I could use the physics engine and apply forces to the enemy ships to move them. I'd be into new territory on that, though, so I'm not sure what issues could crop up.

 

If I was doing this, my first thought would be to have off-screen attractors that the ships are moving towards. If those targets are moved around with some animations or whatever, you could probably get some complex patterns.

Share this post


Link to post
Share on other sites

I didn't think of this. I'm going to try that out.

 

 

If I was doing this, my first thought would be to have off-screen attractors that the ships are moving towards. If those targets are moved around with some animations or whatever, you could probably get some complex patterns.

Attractors is an interesting idea... I'm going to look into that I think.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now