clyde

Amateur Game Making Night

Recommended Posts

my faith in the supposed constant that the computer is never wrong and that it's always human-error has been cracked. 

 

I've had a number of issues with Monodevelop/Unity seemingly not re-compiling code and just using whatever is already built. I honestly haven't looked into it much, since resyncing the solution (Assets -> Sync Monodevelop Project) or restarting Unity/Monodevelop seems to fix it but it is kind of annoying. Just one more thing to make me wish I had ~$2000 to get Unity Pro/Visual Studio Pro/UnityVS. Has anyone else encountered this and know of any fixes (or what causes it)?

Share this post


Link to post
Share on other sites

Friday

 

This morning, I am accepting that I may not accomplish this week's goal. I'm having a hard time fully comprehending how my choice system will work. I think I've taken it far enough that I need to learn about how to write text-parsers that will instantiate the stuff I need. The reason I believe this is that as I try to figure out where in the dialogue I want my choices to direct to, I'm starting to think that I need discrete dialogues rather than one big page. If I use one big page and one single array for all of the dialogue, then I'll be concerned that one dialogue may overlap and replace a portion of another dialogue. My conclusion is that my dialogue system should essentially be a page of series of lines that you flip through (by clicking the mouse) that leads to a single choice menu that determines which loads a different page of a series of lines and so on. I'm going to watch this video and then try to do it that way.

 

Edit:

Then I watched this one.

 

Uh-oh, this guy's thoughtful pauses, patient thoroughness and general paternal pleasantness is going to encourage me to spend a good amount of my day just

. This is actually useful to me. When I started learning how to program, I wanted to make a game as soon as possible. That's understandable, but watching these makes me feel like I've skipped ahead too much. Now that I have a little bit of experience with which to relate to this information, I can get a lot out of it. Fundamentals!

 

2:44 P.M.

 

Watching that guys videos is making me want to organize my visual novel script. I'm trying to split it into multiple classes, but organization of this stuff is really difficult for me to visualize. What I'm doing currently is trying to put the new types, like Said and Option, into a separate script that the one that actually writes all the dialogue to the TextMesh of the textbox. But now I've realized that I might should further separate them, giving Option and Said their own scripts. It's fun, I think I'm learning.

 

5:53 P.M.

After watching a few of that dude's videos (he is fucking adorable to me), I decided to reorganize my code as I try to integrate his style into the way I script; this is also known as "I am fucking crazy."

Here's what I ended up with. I think I'm learning.

using UnityEngine;
using System.Collections;

public class Option
	{
	string message;
	string jumpTo;
	
	//Constructor
	public Option(string message, string jumpTo)
	{
		this.message=message;
		this.jumpTo=jumpTo;
	}
	public string GetMessage(){
		return message;
	}
	public string GetJumpTo(){
		return jumpTo;
	}
}

using UnityEngine;
using System.Collections;

public class Said
	{
	GameObject whoSays;
	string whatTheySay;
	//Here is the constructor
	public Said(GameObject whoSays, string whatTheySay)
	{
		this.whoSays=whoSays;
		this.whatTheySay=whatTheySay;
	}
	public string GetWhatTheySay()
	{
		return whatTheySay;
	}

}
using UnityEngine;
using System.Collections;

public class DialoguePage : MonoBehaviour 
{
	//This script will be placed on the textbox
		
	//This stuff is for the actual textbox
	GameObject textbox;
	TextMesh textMesh;


	//page number for the dialogue array
	public int page=0;
	//Dialogue array that stores Said(speaker, sentence) pairs
	Said[] dialogue=new Said[500];

	
	//This is a method so that I can easily create Said(speaker, sentence) pairs
	void Say(GameObject whoSays, string whatTheySay)
	{
		//Creates an instance of the Said class
		Said line = new Said (whoSays, whatTheySay);
		//Stores it in the dialogue array at the current page
		dialogue 

 = line;
		//Flips the page for next entry.
		page = page + 1;
	}

	//Sprite used for the choiceBox
	public GameObject choiceBox;
	
	//Choices
	
	//An array of all the options for this page's choice
	ArrayList options= new ArrayList();
	
	//This will be the method with which I add each option to an array of options[].
	public void AddOption(Option option)
	{
		options.Add (option);
	}
	
	//Now a way to access the private variables of Choice
	//It's only necessary when instantiating choiceBoxes.
	
	//temporary GameObject for iteration
	GameObject newBox;
	//The method that will instantiate the choice boxes.
	void ShowOptions()
	{
		//Temporary value
		GameObject newBox;
		//Iteration
		for (int i=0; i<options.Count; i++) 
		{
			//Not sure why I have to say "as GameObject" here, but i do because I get this error otherwise:
			//Assets/Scripts/Conversation.cs(74,25): error CS0266: Cannot implicitly convert type `UnityEngine.Object' to `UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?)
			newBox=Instantiate(choiceBox, new Vector3(0,3-i,0), Quaternion.identity)as GameObject;
			//I have to get the 3D text child
			TextMesh textmesh=newBox.GetComponentInChildren<TextMesh>();
			//Now assign the message part of the Option to the text
			//Arraylist retrieval is "Type variable=(Type) arraylist[index];"
			Option tempOption=(Option) options[i];
			textmesh.text= tempOption.GetMessage ();
			//Get the MakeChoice script attached to the gameobject
			MakeChoice makeChoice=newBox.GetComponentInChildren<MakeChoice>();
			//Assign the whatHappens part of the array to the conditional
			makeChoice.jumpTo=tempOption.GetMessage();
			
		}
	}

//An bunch of characters that can be populated in the inspector.
	//Eventually, I will need to find a way for these to fill out automatically
	public GameObject narrator;
	public GameObject character1;
	public GameObject character2;
	public GameObject character3;


	void Awake () {
		//Here we store the textbox GameObject
		textbox = this.gameObject;
		//Now we store the component for the textMesh
		textMesh = textbox.GetComponent<TextMesh> ();

		Say (character1, "Well Weblow");
		Say (character2, "Miss guised");

		Option fall = new Option ("Fall", "fell");
		AddOption (fall);
		Option hike = new Option ("Hike", "hiked");
		AddOption (hike);


		//Last line in Awake() will be resetting the page number back to 0 now that the dialogue array has been populated.
		page = 0;
		textMesh.text = dialogue 

.GetWhatTheySay();
	}


	//Subscribe to MouseClick
	void OnEnable(){
		MouseClick.MouseSelects += Write;
	}
	void OnDisable(){
		MouseClick.MouseSelects -= Write;
	}

	//This will be the method that moves the text along when the mouse is clicked on any item not taged "clickable"
	void Write(GameObject clicked)
	{
		if (clicked==null) 
		{
			//Flip the page
			page=page+1;
			Debug.Log (page);
			if(dialogue

!=null)
			{
				textMesh.text=dialogue

.GetWhatTheySay();
				
			}
			else
			{
				ShowOptions();
			}
		}
	}
}


using UnityEngine;
using System.Collections;

public class DialoguePage : MonoBehaviour 
{
	//This script will be placed on the textbox
		
	//This stuff is for the actual textbox
	GameObject textbox;
	TextMesh textMesh;


	//page number for the dialogue array
	public int page=0;
	//Dialogue array that stores Said(speaker, sentence) pairs
	Said[] dialogue=new Said[500];

	
	//This is a method so that I can easily create Said(speaker, sentence) pairs
	void Say(GameObject whoSays, string whatTheySay)
	{
		//Creates an instance of the Said class
		Said line = new Said (whoSays, whatTheySay);
		//Stores it in the dialogue array at the current page
		dialogue 

 = line;
		//Flips the page for next entry.
		page = page + 1;
	}

	//Sprite used for the choiceBox
	public GameObject choiceBox;
	
	//Choices
	
	//An array of all the options for this page's choice
	ArrayList options= new ArrayList();
	
	//This will be the method with which I add each option to an array of options[].
	public void AddOption(Option option)
	{
		options.Add (option);
	}
	
	//Now a way to access the private variables of Choice
	//It's only necessary when instantiating choiceBoxes.
	
	//temporary GameObject for iteration
	GameObject newBox;
	//The method that will instantiate the choice boxes.
	void ShowOptions()
	{
		//Temporary value
		GameObject newBox;
		//Iteration
		for (int i=0; i<options.Count; i++) 
		{
			//Not sure why I have to say "as GameObject" here, but i do because I get this error otherwise:
			//Assets/Scripts/Conversation.cs(74,25): error CS0266: Cannot implicitly convert type `UnityEngine.Object' to `UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?)
			newBox=Instantiate(choiceBox, new Vector3(0,3-i,0), Quaternion.identity)as GameObject;
			//I have to get the 3D text child
			TextMesh textmesh=newBox.GetComponentInChildren<TextMesh>();
			//Now assign the message part of the Option to the text
			//Arraylist retrieval is "Type variable=(Type) arraylist[index];"
			Option tempOption=(Option) options[i];
			textmesh.text= tempOption.GetMessage ();
			//Get the MakeChoice script attached to the gameobject
			MakeChoice makeChoice=newBox.GetComponentInChildren<MakeChoice>();
			//Assign the whatHappens part of the array to the conditional
			makeChoice.jumpTo=tempOption.GetMessage();
			
		}
	}

//An bunch of characters that can be populated in the inspector.
	//Eventually, I will need to find a way for these to fill out automatically
	public GameObject narrator;
	public GameObject character1;
	public GameObject character2;
	public GameObject character3;


	void Awake () {
		//Here we store the textbox GameObject
		textbox = this.gameObject;
		//Now we store the component for the textMesh
		textMesh = textbox.GetComponent<TextMesh> ();

		Say (character1, "Well Weblow");
		Say (character2, "Miss guised");

		Option fall = new Option ("Fall", "fell");
		AddOption (fall);
		Option hike = new Option ("Hike", "hiked");
		AddOption (hike);


		//Last line in Awake() will be resetting the page number back to 0 now that the dialogue array has been populated.
		page = 0;
		textMesh.text = dialogue 

.GetWhatTheySay();
	}


	//Subscribe to MouseClick
	void OnEnable(){
		MouseClick.MouseSelects += Write;
	}
	void OnDisable(){
		MouseClick.MouseSelects -= Write;
	}

	//This will be the method that moves the text along when the mouse is clicked on any item not taged "clickable"
	void Write(GameObject clicked)
	{
		if (clicked==null) 
		{
			//Flip the page
			page=page+1;
			Debug.Log (page);
			if(dialogue

!=null)
			{
				textMesh.text=dialogue

.GetWhatTheySay();
				
			}
			else
			{
				ShowOptions();
			}
		}
	}
}


using UnityEngine;
using System.Collections;

public class DialoguePage : MonoBehaviour 
{
	//This script will be placed on the textbox
		
	//This stuff is for the actual textbox
	GameObject textbox;
	TextMesh textMesh;


	//page number for the dialogue array
	public int page=0;
	//Dialogue array that stores Said(speaker, sentence) pairs
	Said[] dialogue=new Said[500];

	
	//This is a method so that I can easily create Said(speaker, sentence) pairs
	void Say(GameObject whoSays, string whatTheySay)
	{
		//Creates an instance of the Said class
		Said line = new Said (whoSays, whatTheySay);
		//Stores it in the dialogue array at the current page
		dialogue 

 = line;
		//Flips the page for next entry.
		page = page + 1;
	}

	//Sprite used for the choiceBox
	public GameObject choiceBox;
	
	//Choices
	
	//An array of all the options for this page's choice
	ArrayList options= new ArrayList();
	
	//This will be the method with which I add each option to an array of options[].
	public void AddOption(Option option)
	{
		options.Add (option);
	}
	
	//Now a way to access the private variables of Choice
	//It's only necessary when instantiating choiceBoxes.
	
	//temporary GameObject for iteration
	GameObject newBox;
	//The method that will instantiate the choice boxes.
	void ShowOptions()
	{
		//Temporary value
		GameObject newBox;
		//Iteration
		for (int i=0; i<options.Count; i++) 
		{
			//Not sure why I have to say "as GameObject" here, but i do because I get this error otherwise:
			//Assets/Scripts/Conversation.cs(74,25): error CS0266: Cannot implicitly convert type `UnityEngine.Object' to `UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?)
			newBox=Instantiate(choiceBox, new Vector3(0,3-i,0), Quaternion.identity)as GameObject;
			//I have to get the 3D text child
			TextMesh textmesh=newBox.GetComponentInChildren<TextMesh>();
			//Now assign the message part of the Option to the text
			//Arraylist retrieval is "Type variable=(Type) arraylist[index];"
			Option tempOption=(Option) options[i];
			textmesh.text= tempOption.GetMessage ();
			//Get the MakeChoice script attached to the gameobject
			MakeChoice makeChoice=newBox.GetComponentInChildren<MakeChoice>();
			//Assign the whatHappens part of the array to the conditional
			makeChoice.jumpTo=tempOption.GetMessage();
			
		}
	}

//An bunch of characters that can be populated in the inspector.
	//Eventually, I will need to find a way for these to fill out automatically
	public GameObject narrator;
	public GameObject character1;
	public GameObject character2;
	public GameObject character3;


	void Awake () {
		//Here we store the textbox GameObject
		textbox = this.gameObject;
		//Now we store the component for the textMesh
		textMesh = textbox.GetComponent<TextMesh> ();

		Say (character1, "Well Weblow");
		Say (character2, "Miss guised");

		Option fall = new Option ("Fall", "fell");
		AddOption (fall);
		Option hike = new Option ("Hike", "hiked");
		AddOption (hike);


		//Last line in Awake() will be resetting the page number back to 0 now that the dialogue array has been populated.
		page = 0;
		textMesh.text = dialogue 

.GetWhatTheySay();
	}


	//Subscribe to MouseClick
	void OnEnable(){
		MouseClick.MouseSelects += Write;
	}
	void OnDisable(){
		MouseClick.MouseSelects -= Write;
	}

	//This will be the method that moves the text along when the mouse is clicked on any item not taged "clickable"
	void Write(GameObject clicked)
	{
		if (clicked==null) 
		{
			//Flip the page
			page=page+1;
			Debug.Log (page);
			if(dialogue

!=null)
			{
				textMesh.text=dialogue

.GetWhatTheySay();
				
			}
			else
			{
				ShowOptions();
			}
		}
	}
}

Share this post


Link to post
Share on other sites

Progress Report for Week #15

 

What were my goals for week #14?

 

What are my goals for Week #14?
-Make a visual-novel template.
Shadowrun is making me want to work on something more narrative based. The sequencer isn't done, but I want to work on progressing toward narrative games. It's been a while since I worked on my visual-novel template, and it's going to be a lot of work to figure out what I was doing with the cameras. I'm just going to rip some of the methods out of that project and make a new visual-novel template. I'm choosing "Make a visual-novel template" as my goal even though it sounds ambitious because I just want something that I can kind of work with by week #15. If I end up with something that is just a background and a couple of GUI.Buttons then fine. I can make something more complex later, I just want to be able to make a little story during week 15 and right now I have a broken weird thing that lerps in and out.

What challenges might I face and how can I prepare for them.
-I'll get ambitious for sure. What I'm going to do tomorrow is write down everything that I want and then order it by priority. On Wednesday I'll start with the highest priority.
Also, I think I'll write more than the Monday progress report. A couple of weeks in a row, I've been nervous about writing this on Monday when I'm tired, and confused about what it is I did in the week prior. More frequent reports may be what I need to stay motivated throughout the week and remember what my process of learning has been. I feel irresponsible about just saying my goal was "learn delegates and events" and then coming back a week later and saying "I learned delegates and events!" Reporting on the iteration may be more useful.

 

Which of my goals did I accomplish?

- I pretty much got as far as I did last time (a month or so ago) with the dialogue-logic for a visual-novel template, but I think it's a bit cleaner. 

Progress may have been made?

 

What happened?

- I wrote out some clear goals and published them in this forum. Then I spend the good part of two days writing a script that would allow me to type in dialogue and characters and that would add them to an array that would provide text for a dialogue-box. It actually does work pretty well, but I have such a hard time figuring out how to properly organize (or as I recently heard it referred to "modularize") my script and I've become a little bit obsessed with it. This week I did gain a much better understanding of constructors. There is a standard process which I am slowly familiarizing myself with where each type of thing gets its own class which includes things that affect it.  The best thing that happened to me this week is that while looking for tutorials on how to write and use a text-parser, I came across

. I adore him. I'm ASMRing* off of this guy's videos so hard. I quickly realized that going through the entirety of this tutorial should take precedence over my project. 

I think what he's doing here is very similar to what my dialogue system will be doing. More importantly, I'm beginning to understand some foundational practices of modularization and how to build your script up in such a way that more complexity will not lead to as much confusion. Turns out that the best way for me to learn this stuff is from someone who reminds me of a sober version of Uncle Albert from

.

tumblr_lr6tj3LdCK1qclstoo1_500.jpg

 

 

What are my goals for Week #15

 

I'm going to finish through this tutorial while looking at my script in between. I've already tried to reorganize it a bit based on this fellow's techniques and perspective, I'd like to do it even more if I can figure out how. I know that near the end of the tutorial he goes into using a text-parser. My plan is to go through that and write my own. Then my dialogue manager will put lines of dialogue into an array whenever a choice-box is selected with the mouse. The choice-box will contain a reference to a specific text-file that the dialogue-manager will then process. I think this is a good idea, because it will help me visualize the branching dialogue better than if I have one long dialogue that has markers for where the jump-points are. 

 

What challenges might I face and how can I prepare for them?

- Sometimes it's hard to implement tutorials when not following them along exactly. I think that I may have to go through the videos without changing anything else about my code, and then watching the videos a second time when I am in need of a reference while I actually am writing the script. 

 

*not really, I don't have ASMR, but I imagine that my enjoyment of the videos are similar in that his voice and style comforts me. 

Share this post


Link to post
Share on other sites

Thursday

 

I'm starting to get somewhere with making a text parser. There was a little bit of confusion involving using Unity's TextAsset functionality. But I just managed to piece together code from Unity forums that allows me to show a .txt file's contents in Debug.Log so it's just a matter of time now. Here is the parser thus far.

void ReadFromTextFile()
	{
		//TextAsset textFile = (TextAsset)Resources.Load("myTextFile"), typeof(TextAsset));
		TextAsset textAsset=(TextAsset)Resources.Load ("visualNovel"), TextAsset;

		string delimiter = ":";
		string[] fullContents=textAsset.text.Split(delimiter[0]);

		for (int i=0; i<fullContents.Length; i++) 
		{
			Debug.Log (i+"   "+ fullContents[i]);
		}
	}

Share this post


Link to post
Share on other sites

Anyone have experience with haxepunk or haxe? I'm considering a jump from Gamemaker to that rather than to Unity, mostly because I'm not really interested in making anything 3d or 3d capable.

Share this post


Link to post
Share on other sites

Progress Report for Week #15

What were my goals for week 15?

I'm going to finish through this tutorial while looking at my script in between. I've already tried to reorganize it a bit based on this fellow's techniques and perspective, I'd like to do it even more if I can figure out how. I know that near the end of the tutorial he goes into using a text-parser. My plan is to go through that and write my own. Then my dialogue manager will put lines of dialogue into an array whenever a choice-box is selected with the mouse. The choice-box will contain a reference to a specific text-file that the dialogue-manager will then process. I think this is a good idea, because it will help me visualize the branching dialogue better than if I have one long dialogue that has markers for where the jump-points are.

What challenges might I face and how can I prepare for them?

- Sometimes it's hard to implement tutorials when not following them along exactly. I think that I may have to go through the videos without changing anything else about my code, and then watching the videos a second time when I am in need of a reference while I actually am writing the script.

Which of my goals did I accomplish?

-I did finish watching the videos. Then I read about using Unity's TextAsset class and implemented that enough to get something from a .txt to show up in a Debug.Log() but it stopped there. At that point I had to figure out how I wanted to format the .txt file so I could write the script to read it. I the considered using Twine's export format and found a few references to doing that online. I found a tutorial on the subject that seems legit, but I didn't look all the way through it yet.

Partially Accomplished

What are my goals for week #16?

-I want to put the weekly progress-report on indefinate hiatus. I'm not sure if I should though.

Why do you want to stop doing weekly progress reports for now?

-I don't think that specific goals are motivating me right now. It's hard to write goals when I think I might just change my mind as soon as I open up Unity.

Why do you want to continue with the weekly progress reports?

- well, when I started typing this one, I had assumed that I did absolutely nothing this week. But looking at where I was at the beginning of the week made me realize that I did make progress. That acknowledgement makes me feel like I'm making progress.

How can I have what I want without the stuff I don't want?

-well I obviously need markers of some sort, but I want to just doodle in Unity. I would just submit dated builds of a single project, but I move around between projects and the builds don't always show the work.

This doesn't make any sense. The progress reports are the only way I have to show myself that I am moving forward. I'm keeping them. If I want more general goals, then I should write more general goals. Why would I stop doing something useful if I enjoy it and it continues to benefit me? I wouldn't. I think I just feel pressure or something, but why would I care? Onward!

What are my goals for week #16?

-doodle some bullshit. Put some words in it too.

-start working on a narrative project that I can just add to and publish incremental builds until it stops working.

-fix the sequencer so it shows that correct amounts in the settings menu.

What difficulties might I have and how can I prepare for them?

-right now, I think this section is the problem.

this.section, I find you tedious. I'm going to stop writing you.

Share this post


Link to post
Share on other sites

I've had a number of issues with Monodevelop/Unity seemingly not re-compiling code and just using whatever is already built. I honestly haven't looked into it much, since resyncing the solution (Assets -> Sync Monodevelop Project) or restarting Unity/Monodevelop seems to fix it but it is kind of annoying. Just one more thing to make me wish I had ~$2000 to get Unity Pro/Visual Studio Pro/UnityVS. Has anyone else encountered this and know of any fixes (or what causes it)?

I think I may now be encountering something that is related to this complaint. I am using the TextAsset functionality to save to a .txt in the Assets folder of the project. When I run the scene in Unity and save to that document, it is saving (I can check this by opening the .txt document in Monodevelop).However, if I have my script making a decision based off of what is in the .txt it will use old data; it only updates when I reopen the .txt in Monodevelop. Like you said, it hasn't really been a problem, but it was kind of confusing and I'm scared it will fuck me up at some point.

Share this post


Link to post
Share on other sites

I won't be doing my progress reports anymore. They have outlasted their use. Now I just want to wander around aimlessly, working on parts of whatever, whenever I feel like it. The purpose of the progress reports has become solely to show me that I am indeed doing things with Unity during the course of the week. I've decided that updating a tumblr with these incremental efforts will do a better job of that. It's here if any one is curious.

http://doodle-plans.tumblr.com/

It's been a good run. Also, if any of y'all have dev-logs on tumblr I'd appreciate it if you listed them so I can subscribe. 

And for the record:

 

 

What were my goals for week #16?


What are my goals for week #16?
-doodle some bullshit. Put some words in it too.
-start working on a narrative project that I can just add to and publish incremental builds until it stops working.
-fix the sequencer so it shows that correct amounts in the settings menu.
 

 

Which of my goals did I accomplish?

-All of them. 

Share this post


Link to post
Share on other sites

I just wanted to take a moment to complain publically about how I understand that version-control is important, but I am not looking forward to taking the time necessary towards figuring out how to impliment it. I tried using Github last night and was like "whoa, whoa, whoa there buddy. A little much involved here don't you think." I was just expecting to drag some script files into a folder or something. I'm considering just making a new folder titled with the date in dropbox every time I want to commit, and just uploading the scripts.

Share this post


Link to post
Share on other sites

I think I'm probably just being lazy. I just needed to cry a little bit. Still, suggestions are welcome. I think the command line part intimidated me a bit. I was thinking it would just be a matter of ticking the box on a folder's properties to "share" and then just going about your business.

Share this post


Link to post
Share on other sites

There are programs to alleviate the command-line heaviness of Git and SVN. Personally I prefer Git to SVN, but that's largely because I'm more used to it (though there are actual legitimate reasons to prefer one over the other).

Unfortunately, I can't remember any of said programs right now. I'm the worst.

Share this post


Link to post
Share on other sites

I work with SVN every day but I still hate setting up source control myself. (I used Mercurial the one time I decided to do better than dropbox, and it's been alright so far -- but I don't really know how easily it could be made to work with Unity.)

Share this post


Link to post
Share on other sites

SVN is always a bit of a pain since I have to trust in the fact that it understands what I changed and that it doesn't do something weird with files I know nothing about, but that said, TortoiseSVN has been nice to me so far, it's 'fairly' easy to set up a local repository to keep a backup in case I do something dumb and irreversible. But the most pleasant backup method so far was just zipping up the project folder every night and putting it in my dropbox. 

Share this post


Link to post
Share on other sites

That looks great! (I was surprised when the mirror light and other lights turned on; it's just like getting in a real new car and sitting there for a minute making sure you know what all the knobs do before you start moving =).

 

Once I can get a couple more good working sessions in, I think I will have a tiny playable section of a game about being bossed around in foreign languages and chasing chickens. (With hilarious placeholder many-things, naturally). But so far everything about it has taken more time than expected, so -- someday. =T How thrilling!

Share this post


Link to post
Share on other sites

It just now occurred to me that I could make a 2D platform scene by just putting a picture of a landscape in the background, locking the camera, and drawing collider boxes in the places where the character would be able to stand.

Share this post


Link to post
Share on other sites

I just copied Sinus.cs from this tutorial and I suddenly feel so incapable. I can read much of it, but I don't understand how it works. I feel so envious of Amaury La Burthe and Damien Hen right now. 

I can't believe it makes sound. I'm just taking a moment to admit that I feel this way so that I can move on. I'm going to try and study SInus.cs until I understand all this math stuff. I can't believe it worked. If anyone wants to point out things in it, feel free.

Here are some initial questions I have:

-Why the fuck is π involved?

-What is the increment doing?

-What is the phase doing?

 

I'm so jealous right now. I want to be smart.

using UnityEngine;
using System;  // Needed for Math

public class Sinus : MonoBehaviour
{
  // un-optimized version
  public double frequency = 440;
  public double gain = 0.05;

  private double increment;
  private double phase;
  private double sampling_frequency = 48000;

  void OnAudioFilterRead(float[] data, int channels)
  {
    // update increment in case frequency has changed
    increment = frequency * 2 * Math.PI / sampling_frequency;
    for (var i = 0; i < data.Length; i = i + channels)
    {
      phase = phase + increment;
    // this is where we copy audio data to make them “available” to Unity
      data[i] = (float)(gain*Math.Sin(phase));
    // if we have stereo, we copy the mono data to each channel
      if (channels == 2) data[i + 1] = data[i];
      if (phase > 2 * Math.PI) phase = 0;
    }
  }
} 

Share this post


Link to post
Share on other sites

I'm by no means an expert code guy but I can give it a shot.

 

I think what it's doing is storing data for a sine wave in an array for it to be interpreted later by something that loops through the data[] array, and interprets gain to make sounds.

 

The phase is the point on the sine wave measured in radians, which increases based on the frequency and sampling frequency (not sure what either of those things are, I'm assuming frequency has to do with pitch?). At every increment of phase, the sine of it is taken and multiplied by the gain, which means that every value on a sine wave with the amplitude of the gain is being put into the data[] array at a resolution determined by the frequency and sampling frequency.

 

Pi is in there to make sure that the phase doesn't increase over 2pi, at which point it'll reset to 0 so that it'll repeat that same section of the sine wave and keep the value of phase in check (I think it doesn't matter that much because sine is cyclical).

 

Hope my explanation wasn't too incomprehensible.

Share this post


Link to post
Share on other sites

Thanks Blambo. Yeah, frequency is how many times the oscillation happens per second which determines pitch.

I also contacted my mathematician friend and he told me that sine-wavelengths are measured in pi. He included a diagram to show how a complete sine-wave is two*pi long. That helped me figure out what you said here. It's fascinating isn't it. The line that assigns a value to increment is saying "when we have a sine-wave repeating [frequency] times per second, we need to multiply frequency of the wave by the wavelength ( to get the total length of a second's worth of the repeating sine-wave) and then divide it by how many times a second we retrieve a sample in order to know where to draw the sample from." Then the phase is just a counter for the increments. Coding is so interesting.

Share this post


Link to post
Share on other sites

Ah yeah that makes sense. I feel like this is one of those procedures that would take lots and lots of thought to figure out from scratch.

 

I'm curious about how that thing that interprets the data works now.

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