SecretAsianMan

Unity Tutorials

Recommended Posts

So the point is to take a random number, and apply logic to it, say if the first two digits are greater than 50, make a large map, or something? I can see that. I'll think of how to use the number in different ways to make sure that I'm not always going to get the same types of map. they can't all rely on the size of the number. I'll let you know how it goes, and I'll keep reading the nature of code for more ideas.

Share this post


Link to post
Share on other sites

I've been toying with the idea of a random seed for generating enemy patterns for stages in a shmup.  For me it would be pretty easy I'd probably work in strings of waves that I know work well together then assigning each string to a value in an array, generating the seed, and matching individual seed values to spots in the array for the spawn order.  I'd probably also pair the spawn wave with a random value to spawn along the X-axis, to increase the variation.

 

...of course first I need to create working enemy movement patterns.

Share this post


Link to post
Share on other sites

So the point is to take a random number, and apply logic to it, say if the first two digits are greater than 50, make a large map, or something? I can see that. I'll think of how to use the number in different ways to make sure that I'm not always going to get the same types of map. they can't all rely on the size of the number. I'll let you know how it goes, and I'll keep reading the nature of code for more ideas.

(I'm not entirely sure if you're confused with the general process of turning random numbers into useful values or if you think that a single random value is supposed to determine an entire map, or if I'm misreading your post completely, but I hope this helps.)

 

There's a good explanation of seeded random number generation in the API, but the gist is that after you set a pseudorandom number generator's seed, it will always generate the same sequence of random numbers. So you would first seed the pseudorandom number generator and then generate as many random numbers as you need to define the world. (e.g. the first number for the map's width, second for the height, third for the palette, etc.)

 

Note that if you want the same results, you also need to make sure that you use the sequence the same way each time.

 

An example: Imagine a room with two exits. Both are behind closed doors and the player cannot see into the next rooms. If your code only randomly generates a room at the moment when the player opens a door, then the overall map will be different depending on which door the player enters first. The solution is to generate the entire map beforehand.

 

Another example: Imagine a level-based platform game like Spelunky. You use a seeded RNG to generate the first level, then call the same RNG in-game to get the enemies to move randomly around. The number of times you call the RNG for enemy movement isn't predictable, because it depends in part on how long the player remains in the level and when they kill each enemy. If you only generate the second level at the moment the player beats the first level, then the second level will be different for most players, since the seeded RNG will be in a different place in its sequence. The solution is to either use a different RNG for level generation than in-game stuff (that you don't need to be as deterministic), or to generate every level beforehand.

Share this post


Link to post
Share on other sites

Ok, I think I get it. The following code will be ran before the each level is loaded. 

 

Editted to fix crappy code.

 

 

using UnityEngine;
using System.Collections;

public class MapGen : MonoBehaviour {
    public int seed = 100;
    private float[] noiseValues;

    void Start() {
        Random.seed = seed;
        noiseValues = new float[5];
        int i = 0;
        while (i < noiseValues.Length) {
            noiseValues[i] = Random.value;
            i++;
         }

        int mapWidth = SetMapDimension (noiseValues [0]);
        int mapHeight = SetMapDimension (noiseValues [1]);
        SetChanceOfSea (noiseValues [2]);
        SetRiverAmount (noiseValues [3]);
        SetCharacterLimit (noiseValues [4]);
    }
    
    void SetMapDimension (float randomValue) {}
    void SetChanceOfSea (float randomValue) {}
    void SetRiverAmount (float randomValue) {}
    void SetCharacterLimit (float randomValue) {}
}
 

As I have multiple random numbers, I can use them as I see fit, and they won't be influencing one another. That's pretty cool! I'll be setting up a devlog on this shortly, so you can see how this works out.

Share this post


Link to post
Share on other sites

Sorry guys, only just realised I posted on the tutorials rather than the questions section. I'll come back with a worthy tutorial some day to make up. Sorry again!

Share this post


Link to post
Share on other sites

I've been trying to track down an article on Finite State Machines that I had a vague memory of being on Unity Gems (which went down a while ago), and stumbled on a blog where some articles from that site have been reposted. The formatting is a little worse, but there's still some useful stuff in there.

 

https://unitygem.wordpress.com/

 

The FSM article I was looking for is only on archive.org, with some weird formatting issues (though the Unity package is still downloadable so maybe it'll be fine)

 

https://web.archive.org/web/20140702051240/http://unitygems.com/fsm1/

Share this post


Link to post
Share on other sites

Anyone know of good tutorials on lists? I've used arrays before but not much so the more beginner the better. I've watched the official video tutorial but it's a bit fast and doesn't go into much detail or structure.

Share this post


Link to post
Share on other sites

I don't know of any tutorials about lists specifically, but the MSDN docs have a bunch of examples https://msdn.microsoft.com/en-us/library/6sh2ey19(v=vs.110).aspx

 

If you have specific questions I'm happy to answer, feel free to just ping me on irc or whatever.

 

edit: that link seems broken but I clicked it and it worked so unless someone says otherwise I'm not touching it

Share this post


Link to post
Share on other sites

This might be a perspective I have given my CS background, but I find just declaring a list in code and seeing what comes up in the autocomplete good enough. As far as I treat them, they're pretty much better versions of arrays. Happy to help if you have any specific questions.

Share this post


Link to post
Share on other sites

If you're looking for specifically C# tutorials, there are a few channels on youtube you can check out I've found helpful.  One guy in particular went through a step by step implementation of his own

, implementing all the methods you would find in the standard C# class.

 

Edit: I should note however, in order to follow along in that video you'll at least need to have an understanding of generics and arrays, which he has 

 covering.

Share this post


Link to post
Share on other sites

I'm not sure how useful this will be to people, but I found a pretty good primer on how to create a Lock-Step networking system in Unity.  For those that don't know, Lock-Step is a way of aligning the execution of functions and input gathering such that networked computers can run the exact same instance of a program without having to send massive amounts of data over the network.  They are pretty common in RTS games, or other online games that require a large number of objects to be simulated.  The classic article on the subject is written by one of the programmers for Age of Empires, where he goes over the principles and theory behind the functioning of the system.  It's an interesting read even if you never plan on writing your own RTS.

Share this post


Link to post
Share on other sites

Just going to throw this request out there, but if there were a video series going over lighting in Unity 5 I would like to know.

Share this post


Link to post
Share on other sites

I could use that too. I'll look through the live training sessions tommorow; I would think there would be one there.

Share this post


Link to post
Share on other sites

I'm trying to get back into giving Unity ago, but I often find with the Unity tutorials people talk about scripting without explaining a god damn single word of what the code actually means. That's fine as I understand lots of people interested in first time game development might often have some basic knowledge, but I don't. I don't know what a "class" is, I don't know what a "type" is and I don't know what a "loop" is. I'm trying to watch Bob Tabor's C# for beginners tutorials on youtube and they seem fine so far. Does anyone have any more tips or suggestions for this particular area? Especially if it can be implemented into Unity. 

Share this post


Link to post
Share on other sites

When you're talking about the very fundamentals of programming, I would be suspect of any path of study that doesn't have a way for you to practice, some course work to test what you just learned.

Share this post


Link to post
Share on other sites

Honestly, I would recommend staying away from Unity for a bit.

 

Full featured game engines like Unity can be very complex and assume a lot of knowledge of both programming and graphics tech (especially if you're doing anything 3D). When I was getting into this stuff, I knew I would probably eventually end up with Unity but I started with Python and Gamemaker scripting before making the leap.

 

That's probably not sexy but starting smaller is great for learning programming AND learning how to design a game.

 

I'd suggest trying something in Javascript/HTML5 or Python first, and reading language intros for whatever you go with. If you want to stay focused on games, there's a good book on Python/Pygame here (http://inventwithpython.com/pygame/index.html) and honestly just looking through W3 Schools stuff for Javascript ain't too bad either (http://www.w3schools.com/js/js_loop_for.asp). Learning Gamemaker well enough to transition from drag-and-drop to actual scripting would also be a really good intro (if you can stomach the UI), all the general concepts are the same as other languages and you can find plenty of tutorials for both the visual and the scripting.

Share this post


Link to post
Share on other sites

is what helped me make the break-through of understanding what properties, variables, classes, instances, and functions are.

 

I struggled with these concepts for a while even when hearing people explain it fairly well.

I'm sure everyone learns in different ways, but I tried to learn a programming language before working directly in Unity and it never caught. Making things happen in a game I was making was the level of feedback I needed in order to encourage me enough to really need to internalize the concepts.

Share this post


Link to post
Share on other sites

I wanted to share this tutorial that really helped me a lot in my latest project:

 

 

It's a guy "rebuilding" a control scheme that is similar to that of Hotline Miami. I used it for a completely different control scheme and type of interaction, but the core functions and operations he used were extremely useful to me.

 

Subject touched: 2d mouse-based control schemes, top down games 

 

I hope it can help someone else.

Share this post


Link to post
Share on other sites

is what helped me make the break-through of understanding what properties, variables, classes, instances, and functions are.

 

I struggled with these concepts for a while even when hearing people explain it fairly well.

I'm sure everyone learns in different ways, but I tried to learn a programming language before working directly in Unity and it never caught. Making things happen in a game I was making was the level of feedback I needed in order to encourage me enough to really need to internalize the concepts.

 

 

This is exactly the type of thing I've been looking for, thank you!!

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