• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

GAF Learns - Unity [Game Engine]

Vintage

Member
Debugging on Visual Studio is not possible out of the box, but there's a commercial add-on for it: http://unityvs.com/ I don't know how well it works since I don't have VS Pro and it doesn't work with Express (also I probably don't want to pay $100 for something like that at this point).

How recently have you tried Unity? They recently upgraded the MonoDevelop version included with it in 4.3 so it's better than it was... though still hardly perfect. I have some stability issues, but nothing as bad as what you described.

I know about UnityVS, but I'm making games just for fun, not gonna pay 100$ :/
I've tried multiple versions of Unity, form 2.x to latest, 4.3, I had issues with almost every one of them. As I remember, previous code editor was much more stable.
 

Calabi

Member
I have a couple of stupid basic questions if anyone is able to answer.

Is there a kind of template project or an open source one I can use as a guide? I always get lost and confused with how to organize my project, like where to put the code and what to name things.

Also with referering/referencing other objects in the scene from another script, what method do people generally use? Gameobject.find?

Do people really use the inspector to assign variables? What if I then want to reassign them, it doesnt seem like a good idea long term to me.
 

Lautaro

Member
I have a couple of stupid basic questions if anyone is able to answer.

Is there a kind of template project or an open source one I can use as a guide? I always get lost and confused with how to organize my project, like where to put the code and what to name things.

Also with referering/referencing other objects in the scene from another script, what method do people generally use? Gameobject.find?

Do people really use the inspector to assign variables? What if I then want to reassign them, it doesnt seem like a good idea long term to me.

1) How you organize your assets and name them is up to you, just make something that is understandable (I usualy create a folder for scripts, one for textures, other for models, etc. but if your project is too big you may want to divide assets by the scene where they are used and add subfolders).

That said, the Asset Store has several complete projects and starter kits, some of them free that you can use as base. There's also the tutorial projects in the official site.

2) You should try to avoid Gameobject.find because is kind of expensive. If the object is not instantiated you may include it as a public property or variable in the script so you can assign it in the editor instead of in runtime. If it's instantiated I would try to put it in a public variable when is created.

3) Of course, people use the Inspector, it's a central element in Unity. Think of it like the Properties window of Visual Studio, you use it to set starting values for the properties of an object and you can change them during runtime if you need to (I've never changed them though, if I want to set a value at runtime I use a public property with the [HideInInspector] setting).
 

Calabi

Member
1) How you organize your assets and name them is up to you, just make something that is understandable (I usualy create a folder for scripts, one for textures, other for models, etc. but if your project is too big you may want to divide assets by the scene where they are used and add subfolders).

That said, the Asset Store has several complete projects and starter kits, some of them free that you can use as base. There's also the tutorial projects in the official site.

2) You should try to avoid Gameobject.find because is kind of expensive. If the object is not instantiated you may include it as a public property or variable in the script so you can assign it in the editor instead of in runtime. If it's instantiated I would try to put it in a public variable when is created.

3) Of course, people use the Inspector, it's a central element in Unity. Think of it like the Properties window of Visual Studio, you use it to set starting values for the properties of an object and you can change them during runtime if you need to (I've never changed them though, if I want to set a value at runtime I use a public property with the [HideInInspector] setting).

Thanks for the reply.

That means I dont really understand public variables or anything at all.

Here's some rough code I've done that seems to work.

People potato = GetComponent<People>();
gasme.transform.LookAt(potato.poople.transform);

So to access a public variable in another script I need to define a new variable of that script which is a class, then assign the class/script to it. Then I can use that variable to access any public variable in the class/script. That GetComponent confuses me, from the docs I thought it only got the components in the object that its on, but in this case its able to get the component of another script/class.
 

Lautaro

Member
Thanks for the reply.

That means I dont really understand public variables or anything at all.

Here's some rough code I've done that seems to work.

People potato = GetComponent<People>();
gasme.transform.LookAt(potato.poople.transform);

So to access a public variable in another script I need to define a new variable of that script which is a class, then assign the class/script to it. Then I can use that variable to access any public variable in the class/script. That GetComponent confuses me, from the docs I thought it only got the components in the object that its on, but in this case its able to get the component of another script/class.

What?! I think I'm confussing you even more because you are now confussing me.

Have you made some tutorials? Also this book could help you: http://www.amazon.com/dp/184719818X/?tag=neogaf0e-20
 

JeTmAn81

Member
Anyone have any general suggestions on the best way to go about building a Tetris clone in Unity? I've created the tetriminos and have some script to create them and have them drop, but interaction between rigidbodies does not seem to be the way to go so I'm wondering about handling/detecting the interactions between all the pieces.
 

Calabi

Member
What?! I think I'm confussing you even more because you are now confussing me.

Have you made some tutorials? Also this book could help you: http://www.amazon.com/dp/184719818X/?tag=neogaf0e-20

Sorry, lol.

I have tried lots of tutorials, and I've got this book.

http://www.amazon.co.uk/dp/1430234229/

I dont generally learn that much through tuts and things though. I find its best to just get in and start tinkering. I'll try reading the book and look go look back at some of the tuts. I did stop using Unity for a while I probably need to refresh.
 
I have a couple of stupid basic questions if anyone is able to answer.

Is there a kind of template project or an open source one I can use as a guide? I always get lost and confused with how to organize my project, like where to put the code and what to name things.

Also with referering/referencing other objects in the scene from another script, what method do people generally use? Gameobject.find?

Do people really use the inspector to assign variables? What if I then want to reassign them, it doesnt seem like a good idea long term to me.

Generally yes, I try to use Game Object by find. If one object will be regularly referencing a another, I'll make it a private variable and then set it up in start.

IE:

private GameObject cueBall;

start(){

cueBall = GameObject.FindGameObjectWithTag ("YourBall");
}

you can access Public variables by finding the script using the gameObject's getComponent method.

cueBall.getComponent<BallScript>.transform.position = new Vector3(33,1,0);

Alternatively, if you want to call a method, you don't need to reference the script component. Instead you can use the message system. cueBall.SendMessage("reset");

Sometimes I'll use the inspector when I'm prototyping. I like to keep as many things as possible in code, but I can go faster with the inspector often.
 
Anyone have any general suggestions on the best way to go about building a Tetris clone in Unity? I've created the tetriminos and have some script to create them and have them drop, but interaction between rigidbodies does not seem to be the way to go so I'm wondering about handling/detecting the interactions between all the pieces.

Okay, you probably don't want to use Unities physics to create a tetris Clone. Unless you are trying to create the QWOP of tetris clones. Actually, that sounds like a great gamejam idea.

Instead, you are going to want to devise an internal representation for a Tetris screen,then figure out how that maps to Unity's world space.

For example,I'd probably use a matrix, and I would fill in each spot that's filled with a piece from a pattern stored in an object. I'd not worry about making them fall smoothly, instead I'd use Invoke to make them shift down one row at a specified interval.
 

Calabi

Member
Ok thanks electricpirate.

I'm going to have to iterate through several objects, I think I can work that out though.

I wasnt aware of the send message thing that sounds handy.
 
Ok thanks electricpirate.

I'm going to have to iterate through several objects, I think I can work that out though.

I wasnt aware of the send message thing that sounds handy.

Send Message can clean up the code really nicely.

For iterating, if you can, store things in List<ObjectType>. (You need to have using System.collections.generic at the top). Templated Lists will help avoid a lot of errors and give you some nice features.
 

Jarate

Banned
Im going to try and learn this shit since I have a few game ideas ive been throwing around in my head

I have incredibly limited experience with programming, what should I attempt to learn if I want to learn to create some vidya

I wanna try making a Tecmo Bowl clone first, so how difficult do you guys think that would be?
 
Im going to try and learn this shit since I have a few game ideas ive been throwing around in my head

I have incredibly limited experience with programming, what should I attempt to learn if I want to learn to create some vidya

I wanna try making a Tecmo Bowl clone first, so how difficult do you guys think that would be?

The tutorials on Unity's website are decent enough, you could probably start from there.

A Temco Bowl clone would be pretty difficult for someone with limited experience. I'd say start with a few really small projects (Pong or following a tutorial project would be a decent start) that you can learn from before trying to tackle that.
 
Im going to try and learn this shit since I have a few game ideas ive been throwing around in my head

I have incredibly limited experience with programming, what should I attempt to learn if I want to learn to create some vidya

I wanna try making a Tecmo Bowl clone first, so how difficult do you guys think that would be?

Considering it took the dudes who made Football Heroes (which is a Tecmo clone) like 3 years to make their game (albeit not using Unity) I'm thinking the degree of difficulty would be pretty high.
 

JeTmAn81

Member
Okay, you probably don't want to use Unities physics to create a tetris Clone. Unless you are trying to create the QWOP of tetris clones. Actually, that sounds like a great gamejam idea.

Instead, you are going to want to devise an internal representation for a Tetris screen,then figure out how that maps to Unity's world space.

For example,I'd probably use a matrix, and I would fill in each spot that's filled with a piece from a pattern stored in an object. I'd not worry about making them fall smoothly, instead I'd use Invoke to make them shift down one row at a specified interval.

Thanks for the advice. Yeah, it became apparent to me that just using physics was not going to work very well. Though it does actually seems like that should be possible, assuming you know how to constrain the movements of the pieces so they don't fall out of the play area.

I guess as I was contemplating the other idea of simply using something like an array to keep track of where all current tetris blocks should be, I wasn't sure how that would interact with the actual tetrimino objects that I'd built, which are GameObjects made up of multiple cubes tied together. Would it be best to simply draw in each individual cube (which would fit into one spot in the array) where it's supposed to show up on the game area rather than trying to manage actual tetrimino-shaped objects?
 

BibiMaghoo

Member
Quick question for those in the know:

Can I use a plain with no 'sides' as a navmesh? By this I mean a simple flat plain being baked?

I say this because I did exactly that, but the nav agent doesn't seem to know where the edges are. Do I need to build sides for the plain before baking, like with just some simple rectangles or something?

And secondly, If I disable the renderer on the object used to bake the mesh, will is disable the mesh?
 

Xun

Member
Just decided to download it.

I'm looking to make a game that's been in my head for a while with a friend, but I don't have any knowledge or knowhow into making it (outside of the art/animation).

I'll have to check out the tutorials...
 
Does any one know of any tutorials (or have any experience) in programming Rhythm games at all?
I've been looking around for tutorials and can't find exactly what I'm looking for.

The other night I based button presses on Intervals judged on the audio tracks sample time, but the moment I tried to put multiple intervals and cycling through them, it broke horribly.
 

Wow thanks heaps, that's a great example, I'll grind through their channel later tonight as wel.
It's not exactly what the core of gameplay I'm after but I will need to use that eventually.
I'll be honest some of the stuff mentioned in that video went straight over my head, any resources that touch on audio programming?

Just an example in my head, if there's a track running continuously throughout a level and I want to give four different points in the track for the play to hit (let's say with a shoulder button) and then get the code to "do things". Where/what should i be looking at to figure that out?
 

Skinpop

Member
Are there any good tutorials out there for writing various shaders?

http://www.youtube.com/user/animate4evr/videos?flow=grid&view=0

should be a decent start.

Shaders are great fun. I've been writing my own physically based shader which actually look pretty nice(might share the source if anyone's interested) but I'm kinda blocked by the issue of Unity not supporting HDR cube maps. RGBM seems to be the way to do it but haven't gotten around to implementing a pipeline for generating rgbm cubemaps yet.

Anyone know how to import custom mip-maps levels into unity?
 
Just an example in my head, if there's a track running continuously throughout a level and I want to give four different points in the track for the play to hit (let's say with a shoulder button) and then get the code to "do things". Where/what should i be looking at to figure that out?

Quick idea for implementation (if I understood you correctly): Store a list of time codes between which the user should press the button. So you'd have 4 entries, all of them with their own start and end times. Then when the user presses a button, check if the track's current position is between an entry's start and end positions. The current time of the music can be queried from the AudioSource component.

Going through a list of enties on every button press is a bit silly, though. You could optimize it by having the list sorted by the start times and then only checking against the first entry, and remove the first entry of the list when its end time has been passed.
 
Quick idea for implementation (if I understood you correctly): Store a list of time codes between which the user should press the button. So you'd have 4 entries, all of them with their own start and end times. Then when the user presses a button, check if the track's current position is between an entry's start and end positions. The current time of the music can be queried from the AudioSource component.

Going through a list of enties on every button press is a bit silly, though. You could optimize it by having the list sorted by the start times and then only checking against the first entry, and remove the first entry of the list when its end time has been passed.

Hmm, I KIND OF understand what you're saying, after that vid was posted I looked around for general "rhythm game" type of programming and I found a really use line of code which converts audio.timeSamples to 1/8 note notation.
After that I made an array of notes (eg. 0, 3, 4, 5, 6) which are supposed to represent points of time in notation (not time, if that makes sense).

The issue I'm having now is figuring out how to use the notation time as an argument.
So example, if the noteTime (audio.timeSamples \ sampleRate * BPM * 1/60 * 4)
is equal to the next array position, iterate to the next.
Right now, it's staying at 0.

I'm still trying to get my head around programming in general so I wouldn't be surprised if it's a simple fix.
 
First question, what types are you using for those values? Division in particular can cause problems when you're doing calculations with integer values, since a value between 0 and 1 (say 61/60) will always result in 0, anything between 1 and 2 will result in 1 etc.. I don't know how this works in UnityScript (I know it has dynamic types, but I'm not sure how they behave), but at least in C# it would be safest to use floats.

Another problem may be that you're trying to compare those values using == notation. So notetime(params) == array[1] etc.? This won't work, because you're very unlikely to hit the exact sample time related to your specified note time - the audio file probably has 44100 samples per second while your game updates and performs the check only 60 times per second. It would be better to use greater/smaller than comparison, such as:
if(notetime(params)) >= array[1]) perform_action;

You'd of course need to make sure that action is only done once, so again you could either remove entries while you progress or keep track of which entry you're comparing.
 
First question, what types are you using for those values? Division in particular can cause problems when you're doing calculations with integer values, since a value between 0 and 1 (say 61/60) will always result in 0, anything between 1 and 2 will result in 1 etc.. I don't know how this works in UnityScript (I know it has dynamic types, but I'm not sure how they behave), but at least in C# it would be safest to use floats.

Another problem may be that you're trying to compare those values using == notation. So notetime(params) == array[1] etc.? This won't work, because you're very unlikely to hit the exact sample time related to your specified note time - the audio file probably has 44100 samples per second while your game updates and performs the check only 60 times per second. It would be better to use greater/smaller than comparison, such as:
if(notetime(params)) >= array[1]) perform_action;

You'd of course need to make sure that action is only done once, so again you could either remove entries while you progress or keep track of which entry you're comparing.


Code:
void Start () {
		 
		beatArray = new int[] {0, 3, 4, 7, 8, 11, 13, 15, 16};
		beatOn = false;
	}

void Update () {
		
		audioTime = audioSrc.audio.timeSamples / 44100.0f;
		BeatCycle();
		SixteenthNote();
		sixNoteInt = (int)Mathf.CeilToInt(sixNote);	
	}

void SixteenthNote()
	{
		sixNote = audioTime * BPM * (1f / 60f) * 4.0f;
		measureTime = sixNote;	
	}

void BeatCycle()
	{
		for(int i = 0; i == sixNoteInt; i++)
		{
			Debug.Log(beatArray[i]);
			Debug.Log(sixNoteInt);
		}
		
	}

Probably best off just to show the code I've done so far with it. (leaving variable declarations out of course, the beatarray is an int array due to having issues with using floats with an array.)

I've tried converting sixNote into ints (sixnoteint) but it's just staying at 0.
 
Have you tried just checking the value audioSrc.audio.timeSamples returns to see if you the reference works correctly? I can't immediately figure out anything else that would cause the value to stay at 0, going through the script in my head assuming 120 BPM it should be at 8 just before 1 second has passed (due to the ceil function).

edit: Also, how about just audioSrc.timeSamples (depending on what the reference is like)?

edit2: Wait no, the for loop is wrong. What you're doing is giving the variable i the value 0, and doing the for loop as long as i equals sixNoteInt. This means that as soon as sixNoteInt isn't 0, you don't run the for loop. You would want something else than sixNoteInt in the for loop's condition, for example the array's size (and then you'd compare i < beatArray.Length). Though this would print all the array values on each update and the current value of sixNoteInt after each of them.
 
Have you tried just checking the value audioSrc.audio.timeSamples returns to see if you the reference works correctly? I can't immediately figure out anything else that would cause the value to stay at 0, going through the script in my head assuming 120 BPM it should be at 8 just before 1 second has passed (due to the ceil function).

edit: Also, how about just audioSrc.timeSamples (depending on what the reference is like)?

edit2: Wait no, the for loop is wrong. What you're doing is giving the variable i the value 0, and doing the for loop as long as i equals sixNoteInt. This means that as soon as sixNoteInt isn't 0, you don't run the for loop. You would want something else than sixNoteInt in the for loop's condition, for example the array's size (and then you'd compare i < beatArray.Length). Though this would print all the array values on each update and the current value of sixNoteInt after each of them.

Cool, thanks! That fixed the array problem, but what I'm after is for the array to only increment when the current place in the notation matches the stored eighth note.
So like this

Stored Note (where I want the player to press a button)

0 3 4 7 8

0 1 2 3 4 5 6 7 8

^^ Current Place in the "measure" so to speak
*edit* The post didn't keep the spacing between the numbers but each number lines up with each other. *edit*

So when it reaches the 3rd note and a button is pressed, I want the array to advance to the 4th note to be pressed, when it reaches the 4th note and a button is pressed, and so on
 

Oblivion

Fetishing muscular manly men in skintight hosery
Of course these assholes would come out with tutorial videos a whole year after I downloaded the stupid thing...

Question: I know this program is really good if you want to do level design, but I'm curious, can you also create characters and movable objects as well? What are the limits with this software?
 
Of course these assholes would come out with tutorial videos a whole year after I downloaded the stupid thing...

Question: I know this program is really good if you want to do level design, but I'm curious, can you also create characters and movable objects as well? What are the limits with this software?

Create characters? As in modelling? No, not at all.

You do not create assets in Unity. You get some primitives such as a cube, a sphere, things like that and with some paid plugin you can do some simple manipulation with it, but you are meant to create objects in a different program.

I am not sure how you mean moveable objects. You can move an object in unity by using code. But you need to create the asset of the object itself somewhere else.

Unity is the place where you bring all the assets together and do things with it.
 

gundalf

Member
Of course these assholes would come out with tutorial videos a whole year after I downloaded the stupid thing...

Question: I know this program is really good if you want to do level design, but I'm curious, can you also create characters and movable objects as well? What are the limits with this software?

Do you mean with "this program" Unity? Because Unity comes with no Level Editor.
You can either Buy from cgcookie the Prototype AddoOn to make some BSP Style Levels or build yourself Modular Assets with your favorite 3D Tool (Blender, Maya, etc.) and import them to your Project.
 

Oblivion

Fetishing muscular manly men in skintight hosery
Create characters? As in modelling? No, not at all.

You do not create assets in Unity. You get some primitives such as a cube, a sphere, things like that and with some paid plugin you can do some simple manipulation with it, but you are meant to create objects in a different program.

I am not sure how you mean moveable objects. You can move an object in unity by using code. But you need to create the asset of the object itself somewhere else.

Unity is the place where you bring all the assets together and do things with it.

Do you mean with "this program" Unity? Because Unity comes with no Level Editor.
You can either Buy from cgcookie the Prototype AddoOn to make some BSP Style Levels or build yourself Modular Assets with your favorite 3D Tool (Blender, Maya, etc.) and import them to your Project.

Well, then. Seems I'm rather ill informed on what Unity's actually supposed to do.
 
Cool, thanks! That fixed the array problem, but what I'm after is for the array to only increment when the current place in the notation matches the stored eighth note.
So like this

Stored Note (where I want the player to press a button)

Code:
0        3  4        7  8

0  1  2  3  4  5  6  7  8

^^ Current Place in the "measure" so to speak

So when it reaches the 3rd note and a button is pressed, I want the array to advance to the 4th note to be pressed, when it reaches the 4th note and a button is pressed, and so on
Ok, so.. You store the current index of the stored note array, with starting value 0. Then on update you do the following comparison (or similar):
Code:
if(buttonPressed && sixNoteInt == beatArray[currentIndex])
{
    SuccessfulButtonPressAction();
    currentIndex++;
}
Does this look like it'd do what you want to? The problem is that if the user misses the button press they won't be able to press on any following beats either, since the index now always points to the missed beat. Maybe this is closer to what you want:
Code:
for(int i = 0; i < beatArray.Length; i++)
{
   if(buttonPressed && sixNoteInt == beatArray[i])
   {
      SuccessfulButtonPressAction();
   }
}
Then there's all kinds of additional things to add, like not letting the user press the button multiple times, something to do when the user fails pressing the button etc...
 
Ok, so.. You store the current index of the stored note array, with starting value 0. Then on update you do the following comparison (or similar):
Code:
if(buttonPressed && sixNoteInt == beatArray[currentIndex])
{
    SuccessfulButtonPressAction();
    currentIndex++;
}
Does this look like it'd do what you want to? The problem is that if the user misses the button press they won't be able to press on any following beats either, since the index now always points to the missed beat. Maybe this is closer to what you want:
Code:
for(int i = 0; i < beatArray.Length; i++)
{
   if(buttonPressed && sixNoteInt == beatArray[i])
   {
      SuccessfulButtonPressAction();
   }
}
Then there's all kinds of additional things to add, like not letting the user press the button multiple times, something to do when the user fails pressing the button etc...

Damn, that's awesome. Thank you! I'm gonna try this when I finish work.
So what I'm gathering from this is that the for loop iterates ONCE, because there's an argument inside the loop rather than just printing all the values at once?
That's been my problem is that the moment the loop starts, it spews out all the values at once and doesn't limit the iteration in condition to it's respective place in the notation.
 

213372bu

Banned
Quick question. I've been thinking about learning to program in Unity but the only real experience I have is with really simple flash games and some web browser in C++, is Unity a good place for me to start? Is it easy for me to learn stuff in Unity and branch into other stuff?
 
Quick question. I've been thinking about learning to program in Unity but the only real experience I have is with really simple flash games and some web browser in C++, is Unity a good place for me to start? Is it easy for me to learn stuff in Unity and branch into other stuff?

I don't know too much about Unity syntax, or versatility as I am just looking to get in myself. However as a senior computer science major, I'd say you should probably start learning Java, or C++.
 

Lautaro

Member
Quick question. I've been thinking about learning to program in Unity but the only real experience I have is with really simple flash games and some web browser in C++, is Unity a good place for me to start? Is it easy for me to learn stuff in Unity and branch into other stuff?

Branching in other stuff? I say that if you want to get good in Unity you better focus on it instead of using it as a start. Unity is not complex and I think you are good enough if you know some coding (especially C#) but if you want to take advantage of it's features you'll need to give it your complete attention (if you are good at C++, you are probably ready enough to start with some tutorials).
 
Damn, that's awesome. Thank you! I'm gonna try this when I finish work.
So what I'm gathering from this is that the for loop iterates ONCE, because there's an argument inside the loop rather than just printing all the values at once?
That's been my problem is that the moment the loop starts, it spews out all the values at once and doesn't limit the iteration in condition to it's respective place in the notation.
Yeah, the way you should use a for loop is that you go through all the items in an array/list and then inside the loop check if some other condition matches (or do something else related to the items like adding them to the same variable etc.). The condition used in the for loop should just about never contain a variable that can't be guaranteed to be between 0 and the size of the array, and it's quite often something directly related to the length of the array (array.Length, array.Length/2 or similar).

This might explain how a for loop works. These two are equivalent structures:
Code:
1:
for(int i = 0; <condition>; i++)
{
   <do_something>
}

2:
int i = 0;
while(<condition>)
{
   <do_something>
   i++;
}
 
Yeah, the way you should use a for loop is that you go through all the items in an array/list and then inside the loop check if some other condition matches (or do something else related to the items like adding them to the same variable etc.). The condition used in the for loop should just about never contain a variable that can't be guaranteed to be between 0 and the size of the array, and it's quite often something directly related to the length of the array (array.Length, array.Length/2 or similar).

This might explain how a for loop works. These two are equivalent structures:
Code:
1:
for(int i = 0; <condition>; i++)
{
   <do_something>
}

2:
int i = 0;
while(<condition>)
{
   <do_something>
   i++;
}

Ahhh no I get ya, the initial "for" argument doesn't actually DO anything per se, it just indexes (so to speak) all the array values to be used by the code inside the loop.
I tried it last night and it worked...for the most part, perfectly.
The problem I face now is the sixNote time updates on its own time, where as the array bases its update by...well Update().
Is there a way to change the time or match the time the array updates to sixNote or any faux time?
 

belushy

Banned
Been doing Quill18Creates' "Multiplayer FPS" tutorial. Really learning a lot. I have no Unity, Modeling or C# experience, but he is pretty good at explaining things. He also purposely gets errors just to help walk you through it.
 

Minamu

Member
I need some help with a project of mine. I'm very new to Unity but have some UDK experience and I'm currently doing the game tutorials on the unity3d website. I have one basic C# uni course behind me (and two basic C++ courses). Essentially, I'm gonna do a cityscape environment (gonna have to buy the props probably) and I need a vehicle of sorts to move from one place to another. The only game interaction is that the player will need to pick one of two pre-determined paths for the vehicle to go down (in real-time). In UDK I'd probably do this with a Matinee animation but I'm not sure if there's anything similar to that in Unity.

Basically I'm emulating the famous "trolley problem" where the player must choose who gets to die and who gets to live, by picking which railroad track a runaway train travels on. On each track there will be animated characters walking around, and the player must choose which group of people gets overrun by the train.
 
Hey gaf, new unity user and I don't have any development or coding ability and I am learning as progressing. I am trying to make a fighting game movement, based on street fighter. Most of the tutorials I found are for shooters or plateformers where the sprites are flipped when going left or right, not explaining how to do a backward animation. Can you help me ? :/
Since I'll have to flip the sprites and commands too, I also need to find a tutorial or some basic explanation of how to add the Y axis to the characters too. Sorry if these are dumb questions but since I am very new to this, I am having a hard time formuling how it should work.
 
Hey gaf, new unity user and I don't have any development or coding ability and I am learning as progressing. I am trying to make a fighting game movement, based on street fighter. Most of the tutorials I found are for shooters or plateformers where the sprites are flipped when going left or right, not explaining how to do a backward animation. Can you help me ? :/
Since I'll have to flip the sprites and commands too, I also need to find a tutorial or some basic explanation of how to add the Y axis to the characters too. Sorry if these are dumb questions but since I am very new to this, I am having a hard time formuling how it should work.

Playing the animation backwards? The sprite will be updated via time so just get the max frame time and deduce time from the animation.

Flipping a sprite is easy. Just scale it by -1 in the X axis.
 
Playing the forward animation doesn't work as it looks weird when used for walking backward. The character sprites I am using :

AOhHOEZ.png

v7XyAsM.png


Since I'll have to use different sprites for vertical jump and forward/back jump, I want to learn how to do it. Here is the code I am using now, with the character having his sprite flipping. I followed this tutorial.

Code:
using UnityEngine;
using System.Collections;
public class RyuControls: MonoBehaviour {

	//We create a variable for maxspeed for the character :
	public float maxSpeed = 2f;

	//We create a variable for facing right when started
	bool facingRight = true;

	//Variable for using the animator is called anim
	Animator anim;

// Use this for initialization
	void Start () 
	{ 
		//We initialize the variable of the animator before anything else
		anim = GetComponent<Animator> ();
	}
	
// Update is called once per frame, FixedUpdate is used instead of Update because of Rigibody.
	void FixedUpdate () {
	
		//How much I am moving ? Horizontal.
		float move = Input.GetAxis ("Horizontal");

		//Call variable anim, set a float called speed (already present in animator) and we tell her to move
		anim.SetFloat ("forward", Mathf.Abs (move));

		//Actually move the character using velocity
		rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);

		//After we start moving, link the movement and the flipping animation
		//If move is greater than 0 and we are not facing right, flip, then opposite
		if(move > 0 &&!facingRight)
				Flip ();
		else if(move < 0 && facingRight)
				Flip ();
	}

//New Function to flip the sprite of the character
	void Flip ()

	{
		//Facing right if is not facing right
		facingRight = !facingRight;
		//Take the actual local scale before doing anything
		Vector3 theScale = transform.localScale;
		//Flip the X axes
		theScale.x *= -1;
		//apply it to the local scale
		transform.localScale = theScale;
	}
}

Sorry about asking such noob questions. All solutions and topic I found did not helped.
 
Playing the forward animation doesn't work as it looks weird when used for walking backward. The character sprites I am using :

AOhHOEZ.png

v7XyAsM.png


Since I'll have to use different sprites for vertical jump and forward/back jump, I want to learn how to do it. Here is the code I am using now, with the character having his sprite flipping. I followed this tutorial.

Sorry about asking such noob questions. All solutions and topic I found did not helped.

Moving backwards will require another state. Create a new Mecanim state called walk backwards and make it trigger when forward is less than -0.1, this will then trigger the back animation

The same thing will need to be done for jumping. A state transition which triggers the jump when a certain button is pressed.
 
Thanks for this, i'll try to make it! I must sound very stupid but since I did artschool instead of computer, I am a bit lost in all this. :[
 
Sorry for double posting, I still need help.
I made what you suggested and it's not working for this reason: the float parameter I added to the animator and that is used on all transition between states (greater than or less than...) never goes under zero. So if move right or left, the number indicated next to the parameter name only goes from 0 to 1, and logically it's only playing the forward state as he is configured to be played if we go above 0.1.

I made a screenshot so it's understandable : http://i.imgur.com/jDRDN0Y.gif
 
Sorry for double posting, I still need help.
I made what you suggested and it's not working for this reason: the float parameter I added to the animator and that is used on all transition between states (greater than or less than...) never goes under zero. So if move right or left, the number indicated next to the parameter name only goes from 0 to 1, and logically it's only playing the forward state as he is configured to be played if we go above 0.1.

I made a screenshot so it's understandable : http://i.imgur.com/jDRDN0Y.gif

This bit is your problem:
Code:
anim.SetFloat ("forward", Mathf.Abs (move));

Mathf.Abs() returns the absolute value (i.e. without the sign) of its parameter, so that's why you always have a positive value there. Just set the float to "move" directly ( anim.SetFloat ("forward", move); ) and it should work.
 
Top Bottom