Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
One thing that will make dealing with quaternions much more intuitive is realizing that they're extremely closely related to axis-angle rotations. Converting from an axis-angle rotation is just:

X = Axis X * sin(angle)
Y = Axis Y * sin(angle)
Z = Axis Z * sin(angle)
W = cos(angle)

Various consequences of that:

quat(X, Y, Z, W) == quat(-X, -Y, -Z, -W), which is used by a lot of algorithms that force W to be positive.

inverse(quat(X, Y, Z, W)) == quat(-X, -Y, -Z, W) OR quat(X, Y, Z, -W)

All rotation quaternions are length 1, so they're great for representing rotations that undergo a ton of transformation because you can always fix the error accumulation by just normalizing it.

Adbot
ADBOT LOVES YOU

Unormal
Nov 16, 2004

Mod sass? This evening?! But the cakes aren't ready! THE CAKES!
Fun Shoe

OneEightHundred posted:

One thing that will make dealing with quaternions much more intuitive is realizing that they're extremely closely related to axis-angle rotations. Converting from an axis-angle rotation is just:

X = Axis X * sin(angle)
Y = Axis Y * sin(angle)
Z = Axis Z * sin(angle)
W = cos(angle)

Various consequences of that:

quat(X, Y, Z, W) == quat(-X, -Y, -Z, -W), which is used by a lot of algorithms that force W to be positive.

inverse(quat(X, Y, Z, W)) == quat(-X, -Y, -Z, W) OR quat(X, Y, Z, -W)

All rotation quaternions are length 1, so they're great for representing rotations that undergo a ton of transformation because you can always fix the error accumulation by just normalizing it.

One thing that's not necessary obvious when you start wacky Euler/matrix/quaternion math, but was pretty :aaaaa: to me when I first learned it a million years ago is that your 3x3 matrix is just literally made up of the 3 vectors that define the 3 axis of the orientation that it will rotate to. Realizing that helped me understand what the gently caress was going on with matrices.

http://renderdan.blogspot.com/2006/05/rotation-matrix-from-axis-vectors.html

Unormal fucked around with this message at 04:01 on Mar 26, 2013

KoRMaK
Jul 31, 2012



In the realm of a 2D fighter game, what should happen to the player that gets hit? Should they be stunned and unable to move for a bit while the other player beats on them? I need to get some good fighting games for reference.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

KoRMaK posted:

In the realm of a 2D fighter game, what should happen to the player that gets hit? Should they be stunned and unable to move for a bit while the other player beats on them? I need to get some good fighting games for reference.
In general, stunned and unable to act is a terrible terrible idea that makes games frustrating and not fun. If you're going to do stunned, you should make it something the player can act to break (by tapping a button, wiggling left-right, etc.) or give them limited options like still being able to move and block while stunned just not attack. But don't put them totally out of control, that's just awful.

Surprise T Rex
Apr 9, 2008

Dinosaur Gum

KoRMaK posted:

In the realm of a 2D fighter game, what should happen to the player that gets hit? Should they be stunned and unable to move for a bit while the other player beats on them? I need to get some good fighting games for reference.

I think the way games like Street Fighter, etc. work is that different moves have different stun times, and take differing amounts of time to actually attack, and to recover from. Obviously this has to be pretty well balanced, though, so that you can't just repeatedly light-jab your opponent into oblivion while they can't act.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
So I'm trying to get into Unity with Futile and I've gone through MattRix's tutorials and started making something of my own but I've already hit a roadblock. For some reason I just can not get my own texture atlas working. Can someone download this thing and tell me what's wrong? It's about as simple as it gets and the error being thrown doesn't help at all.

  • I have all of my atlas files in "\Assets\Resources\Atlases"
  • Here are my files TestAtlas.png and TestAtlas.txt
  • The text file appears to reference everything correctly
  • In my Unity project I have the TestAtlas.png settings as:



Which is the same as in his sample project. In my code I'm calling:
code:
Futile.atlasManager.LoadAtlas("Atlases/TestAtlas");
...and when it runs it throws the following error:
code:
NullReferenceException: Object reference not set to an instance of an object
FAtlas.LoadTexture () (at C:/Users/Public/Documents/Unity Projects/FatOut/Assets/Plugins/Futile/Core/FAtlas.cs:102)
FAtlas..ctor (System.String name, System.String imagePath, System.String dataPath, Int32 index, Boolean shouldLoadAsSingleImage) (at C:/Users/Public/Documents/Unity Projects/FatOut/Assets/Plugins/Futile/Core/FAtlas.cs:79)
FAtlasManager.ActuallyLoadAtlasOrImage (System.String name, System.String imagePath, System.String dataPath) (at C:/Users/Public/Documents/Unity Projects/FatOut/Assets/Plugins/Futile/Core/FAtlasManager.cs:33)
FAtlasManager.LoadAtlas (System.String atlasPath) (at C:/Users/Public/Documents/Unity Projects/FatOut/Assets/Plugins/Futile/Core/FAtlasManager.cs:53)
Main.Start () (at Assets/Scripts/Main.cs:44)
I've tried creating multiple atlases some containing only one image and the same error is being thrown over and over again but I can load his sample atlases just fine. What the hell is going on here?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Set your maxsize to 2048. Your png is 1024x2048. I learned this yesterday after my atlas moved up to the next size in TexturePacker and then all of a sudden, garbled mess where my sprites should be.

Also set your Texture Type as "Texture". See if that helps. Here's my atlas properties:


poemdexter fucked around with this message at 15:58 on Mar 26, 2013

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch

poemdexter posted:

Set your maxsize to 2048. Your png is 1024x2048. I learned this yesterday after my atlas moved up to the next size in TexturePacker and then all of a sudden, garbled mess where my sprites should be.

It doesn't matter. I've tried setting Max Size to its actual size or the biggest like in that screenshot (which is what he does for his atlases) and I get the error either way.

KoRMaK
Jul 31, 2012



Yea it's pretty painful to have a full stun. After I got my AI up I kept wondering "how the hell do I make this more entertaining" because basically the AI gets up next to you and mashes its attack. I thought the idea of a freeze for .5 sec, and then an invincible escape for 1 sec for the player that was hit might work. I also was heavily considering the idea of having a breaking combo. But being able to be hit and rendered unable to attack without a shield sucks. Add a shield/block ability and now it's kind of fun, I would think (I haven't tried yet)

I also have to add a "flee" behavior to the AI so that if it gets dinged a couple times it gets away.

Surprise T Rex posted:

I think the way games like Street Fighter, etc. work is that different moves have different stun times, and take differing amounts of time to actually attack, and to recover from. Obviously this has to be pretty well balanced, though, so that you can't just repeatedly light-jab your opponent into oblivion while they can't act.
So after a player is hit, are they unable to do ANYTHING or are they able to do restricted stuff (block, backup, anything but attack), or is there an invincible escape moment so they can back off?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Yodzilla posted:

It doesn't matter. I've tried setting Max Size to its actual size or the biggest like in that screenshot (which is what he does for his atlases) and I get the error either way.

Recheck my post. I added additional info.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch

poemdexter posted:

Recheck my post. I added additional info.

poemdexter posted:

Also set your Texture Type as "Texture". See if that helps. Here's my atlas properties:



Nope, nothin' doing. Still throws the error.

superh
Oct 10, 2007

Touching every treasure

KoRMaK posted:

After I got my AI up I kept wondering "how the hell do I make this more entertaining" because basically the AI gets up next to you and mashes its attack.

You make the AI hold off and not attack all the time. Make it run away for a bit and do stupid things too. This is the hardest part, it's easy to make an unbeatable unfun AI but it's better to make one that's more complicated and more "realistic."

In Street Fighter if you get hit you're interrupted and "stunned" in a hit state very briefly, a tiny fraction of a second, but if you get hit enough times you enter a real "stun" state. I think whether or not this feels "bad" in the game comes down to how long you stay in this state.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

KoRMaK posted:

So after a player is hit, are they unable to do ANYTHING or are they able to do restricted stuff (block, backup, anything but attack), or is there an invincible escape moment so they can back off?
For basic hits, nearly all fighter games will knock the player back slightly and prevent them from taking any actions for a very short amount of time, after which they're free to do any action. The only major exception is the various "meters" at the bottom, which have become spendable to break out of stun states and escape from a combo. SF's "dizzy" state is much less common and much more controversial.

Infinite combo prevention is a very tricky art and I'm not very well versed on fighter game theory, but usually relaunch combos are prevented by launchers being too slow to hit someone before they're below the effective range, stun combos are prevented by basic attacks chaining into combos that end on something slow (and the opener can't be chained because you have to wait for it to think you're out of the combo or cancel it using something that has a time cost), and specials are often restricted based on where you are in a combo or have prohibitive startup and recovery times that prevent them from being used on standing enemies. A lot of fighters go further and have stun lengths and damage get worse if a combo goes on for too long.

Honestly, it's extremely hard to design a fighter game well unless you understand the theory behind them reasonably well, are making it primarily as a joke (i.e. having a cast of all pop culture references), or you have a Marvel license in which case you can put in as much broken poo poo as you want. :shepface:

OneEightHundred fucked around with this message at 16:37 on Mar 26, 2013

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Yodzilla posted:

Nope, nothin' doing. Still throws the error.

I added your atlas to my code it loaded just fine. Got mario on my screen and everything. Spelling errors somewhere?

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch

poemdexter posted:

I added your atlas to my code it loaded just fine. Got mario on my screen and everything. Spelling errors somewhere?

I just don't know. This is beyond frustrating and I have no idea what the hell is going on. The only code I'm calling is this:
code:
Futile.atlasManager.LoadAtlas("Atlases/BananaGameAtlas");
Futile.atlasManager.LoadAtlas("Atlases/TestAtlas");
I'm not creating any objects, not loading any sprites afterwards, nothing. BananaGameAtlas loads fine but as soon as I try to load my TestAtlas or any other atlas I create it throws that error. I'm using the same files I uploaded and the "image" in TestAtlas.txt is TestAtlas.png which is what's in the folder so I'm completely and utterly stumped.


E: GOD loving DAMMIT now i understand why he has all those atlases with _ScaleNum and how that corresponds to the screen resolution you're running at. gently caress i'm a goddamn idiot

programmin' :smugwizard:

Yodzilla fucked around with this message at 17:08 on Mar 26, 2013

ZombieApostate
Mar 13, 2011
Sorry, I didn't read your post.

I'm too busy replying to what I wish you said

:allears:
I know absolutely nothing about Unity, but I looked up FAtlas.cs and the surrounding area around line 102 looks like this:

code:
	private void LoadTexture()
	{
		_texture = (Texture) Resources.Load (_imagePath, typeof(Texture));

		if(!_texture)
		{
			Debug.Log ("Futile: Couldn't load the atlas texture from: " + _imagePath);	
		}

		_textureSize = new Vector2(_texture.width,_texture.height); <------------ line 102
	}
I would guess you have a log entry that says it couldn't load your atlas from whatever _imagePath is (probably contains your "Atlases/TestAtlas"), so the first thing I would try is play with the path you're providing and see if that fixes it. If it fails to load the texture atlas, _texture would be bad and cause it to crash on line 102 where it tries to reference _texture.width.

Edit: Welp, nevermind :shepface:

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Yodzilla posted:

I just don't know. This is beyond frustrating and I have no idea what the hell is going on. The only code I'm calling is this:
code:
Futile.atlasManager.LoadAtlas("Atlases/BananaGameAtlas");
Futile.atlasManager.LoadAtlas("Atlases/TestAtlas");
I'm not creating any objects, not loading any sprites afterwards, nothing. BananaGameAtlas loads fine but as soon as I try to load my TestAtlas or any other atlas I create it throws that error. I'm using the same files I uploaded and the "image" in TestAtlas.txt is TestAtlas.png which is what's in the folder so I'm completely and utterly stumped.


E: GOD loving DAMMIT now i understand why he has all those atlases with _ScaleNum and how that corresponds to the screen resolution you're running at. gently caress i'm a goddamn idiot

programmin' :smugwizard:

So what was the solution? I didn't do any sort of _scalenum wizardry to my sprite page nor yours and I got a nice mario on my screen. Now I'm paranoid I hosed up somehow. :smith:

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
The problem was that I copied this over from his sample code:
code:
FutileParams fparams = new FutileParams(true,true,false,false);
fparams.AddResolutionLevel(480.0f,	1.0f,	1.0f,	"_Scale1"); //iPhone
fparams.AddResolutionLevel(960.0f,	2.0f,	2.0f,	"_Scale2"); //iPhone retina
fparams.AddResolutionLevel(1024.0f,	2.0f,	2.0f,	"_Scale2"); //iPad
fparams.AddResolutionLevel(1280.0f,	2.0f,	2.0f,	"_Scale2"); //Nexus 7
fparams.AddResolutionLevel(2048.0f,	4.0f,	4.0f,	"_Scale4"); //iPad Retina
fparams.origin = new Vector2(0.5f,0.5f);
Futile.instance.Init (fparams);
Which enables you to have multiple atlases with differently sized versions of the same elements for different device resolutions. While cool, what this was doing was when I ran
code:
Futile.atlasManager.LoadAtlas("Atlases/TestAtlas");
...was that it was looking for TestAtlas_Scale1, TestAtlas_Scale2, etc which didn't exist and was throwing that error.

Now that I know how supporting multiple resolution atlases works I was able to strip out what I don't need for now and load my regular one using just this:
code:
FutileParams fparams = new FutileParams(true,true,false,false);
fparams.AddResolutionLevel(1024.0f,	1.0f,	1.0f,	""); //iPad
fparams.origin = new Vector2(0.5f,0.5f);
Futile.instance.Init (fparams);
Futile.atlasManager.LoadAtlas("Atlases/TestAtlas");
And now it works great.

Opinion Haver
Apr 9, 2007

I think something a lot of fighting games will also do is have the stun time decay as the combo continues, so even if an attack stuns for half a second at the start, it'll only stun for .1 seconds if it's the 10th move or whatever.

xgalaxy
Jan 27, 2004
i write code
Sony getting rid of approval process.
This along with the Unity licenses is making the PS4 very attractive to indies.

Only question is how expensive a dev kit will be.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

OneEightHundred posted:

Honestly, it's extremely hard to design a fighter game well unless you understand the theory behind them reasonably well, are making it primarily as a joke (i.e. having a cast of all pop culture references), or you have a Marvel license in which case you can put in as much broken poo poo as you want. :shepface:

Yeah, the theory of it all boils down to very small tweaks that are largely imperceptible from watching fighting games, and are also hard to perceive whilst casually playing the game too. Add stuff in like jump and roll cancelling (for some 3d fighters) and it all gets very complicated indeed. Basically the key is to penalize, but allow you to come out of problems with good timing and strategy. How that balances to the low end of players takes ALOT of playtesting, and you may as well acknowledge that it's going to be a mess until you have some decent play time on it.

Play good fighting games and attempt to get genuinely decent at one, it's probably the best way to learn if you're looking to make something seriously.

Jewel
May 2, 2009

Maluco Marinero posted:

Play good fighting games and attempt to get genuinely decent at one, it's probably the best way to learn if you're looking to make something seriously.

Basically this, yeah. To make a fighting game you really need to know your stuff. Even the new Skullgirls DLC characters that are being voted for, under each of them they have a big list of inspiration they draw from, maybe 10-20 games each. To make a character or an attack or something you really can't just focus on design, you have to focus on various techniques and intricacies learnt only by seeing a lot of fighting games. They're also hell to make because fighting games are one of the only times you want to make a solid engine before making a solid game, because usually there's only one ruleset that the game goes by, and that ruleset has to be absolutely frame-perfect in all cases.

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.
What's the preferred method of handling savegames (without built-in serialization)? Do you use human-readable formats like XML/YAML so they're easy to debug and maintain but cumbersome? Or do you prefer custom binary formats that are fast and efficient but a pain to work with?

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch

xgalaxy posted:

Sony getting rid of approval process.
This along with the Unity licenses is making the PS4 very attractive to indies.

Only question is how expensive a dev kit will be.

I've heard that Sony is easy to work with regarding dev kit pricing for indie developers. I'm sure it's a case by case thing but that's coming from two devs I've spoken to about cross platform authoring.

Cancelbot
Nov 22, 2006

Canceling spam since 1928

More of a conceptual/what is fun question, I'm essentially ripping off Carnage Heart by building a 2D game where robots are controlled by flow-diagram code.

In case you're not familiar with carnage heart, the "code" that players build looks like this:


It has conditions that relate directly to the bots state, these bots are pretty advanced and can evaluate "if enemy within 15 metres". Branching is achieved with the red/green arrows. But what I'm building is closer to hobby robots than giant anime robots and so my current set of instruction blocks are actually related to something resembling a very basic processor:

Processors determine how many cells you have to code in, the number of variables (registers) and how deep the stack can be;
The IN/OUT commands send/receive raw bytes to simulated devices (motors, sensors etc.) and try to imagine each op as a block in a grid as seen in the image above.
code:
NOP			Do nothing						1 cycle
SET			Set variable to value					1 cycle
IF			Compare variable to another or fixed value		2 cycle
IFJUMP			Compare variable to another or fixed value		3 cycle
IN			Read input pin into variable				1 cycle
OUT			Write variable/constant to output pin			1 cycle
INS			Read input pin into stack				1 cycle
OUTS			Write stack variable to output pin			1 cycle
PUSH			Write variable to stack					1 cycle
POP			Write stack to variable, remove from stack		1 cycle
SETIN			Changes pin to in					2 cycle
SETOUT			Changes pin to out					2 cycle
TOGGLE			Toggles pin						2 cycle
JUMP			Unconditional jump to location				3 cycle
SUB			Jump to location as subroutine				2 cycle
RETURN			Return to last cell in subroutine			2 cycle
WAIT			Pauses execution cycle					1..n cycles
EXIT			Exits execution cycle					1 cycle
INC			Increment variable					1 cycle
DEC			Decrement variable					1 cycle
ADD			Add variable						1 cycle
SUB			Subtract variable					1 cycle
MUL			Multiply variable					2 cycle
DIV			Divide variable						2 cycle
REM			Division remainder					2 cycle
AND			AND variable						1 cycle
OR			OR variable						1 cycle
XOR			XOR variable						1 cycle
I fear I may have leaned too far to the educational side of puzzle/strategy games and should go higher level. So would anyone actually go for babies first assembly language or would moving it back to higher level "Seek, Move, Attack" behaviors be more appealing?

The Gripper
Sep 14, 2004
i am winner

Yodzilla posted:

I've heard that Sony is easy to work with regarding dev kit pricing for indie developers. I'm sure it's a case by case thing but that's coming from two devs I've spoken to about cross platform authoring.
They're pretty good yeah, the debug PS3s cost a little over $1000 USD and if you have a popular game that you want to port to PS3 they often make exceptions and loan consoles at no cost to aid in getting that done.

They have a divide between debug PS3s and their full-featured dev kits (I don't think they even lease full dev kits to anybody other than large studios), so I'm assuming Sony will either stick with that model or make a shift towards how the 360 deals with it - allowing indie developers to deploy to their own consoles for testing (without full debugging features), which would make Unity a very attractive prospect and get a lot more content into the PS3 marketplace.

Edit; compared to Microsoft they definitely treat indie developers as proper clients and actually want them to make games for their platform, instead of the "it's a privilege to make games for the Xbox and we are doing you a favor" attitude Microsoft has. It's unfortunate that it's not as easy to develop for, currently.

The Gripper fucked around with this message at 14:31 on Mar 27, 2013

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Cancelbot: Far be it from me to criticize someone for designing a brutally complicated educational puzzle game, but I think you're underestimating how many blocks like that will be necessary to build up high level behaviors. Can you imagine writing the equivalent of a thousand-line C program in raw, straight-line assembly? If you like the assembly language-like style, design a simpler game that is more suited to OR provide some means of abstraction. You could, for example, allow users to group together cells into subcircuits which could be reused, slowly building up more powerful capabilities.

Cancelbot
Nov 22, 2006

Canceling spam since 1928

Internet Janitor posted:

Cancelbot: Far be it from me to criticize someone for designing a brutally complicated educational puzzle game, but I think you're underestimating how many blocks like that will be necessary to build up high level behaviors. Can you imagine writing the equivalent of a thousand-line C program in raw, straight-line assembly? If you like the assembly language-like style, design a simpler game that is more suited to OR provide some means of abstraction. You could, for example, allow users to group together cells into subcircuits which could be reused, slowly building up more powerful capabilities.

You're right - I think there's two potential games at the moment; higher level robot punching simulator and lower level manipulate an LED to win: the game. Building up sub-components is a good idea as the potential grid space would grow enormously. But you already mentioned that :)

Polio Vax Scene
Apr 5, 2009



SupSuper posted:

What's the preferred method of handling savegames (without built-in serialization)? Do you use human-readable formats like XML/YAML so they're easy to debug and maintain but cumbersome? Or do you prefer custom binary formats that are fast and efficient but a pain to work with?

I've done all of these and serialization is a godsend. Why can't you use it? If you have to choose between the last two stick with XML, "cumbersome" is hardly an issue these days, your only worry should be people editing the save file.

Cancelbot posted:

More of a conceptual/what is fun question, I'm essentially ripping off Carnage Heart by building a 2D game where robots are controlled by flow-diagram code.

Back in 2004 (:corsair:) I remember a game that worked exactly like this made in Game Maker, I believe it was made by a fellow called EricDB, I don't think it had stacks or variables, just the ability to scan for obstacles/enemies in a relative rotation, check fuel/damage status, and move/shoot. Is there any reason you can't start out with look/move commands and expand on them as the game goes on?

Polio Vax Scene fucked around with this message at 14:45 on Mar 27, 2013

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

SupSuper posted:

What's the preferred method of handling savegames (without built-in serialization)? Do you use human-readable formats like XML/YAML so they're easy to debug and maintain but cumbersome? Or do you prefer custom binary formats that are fast and efficient but a pain to work with?

Why don't you use something in-between like messagepack? Fast and efficient but easy to work with.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
What format you use to store the data doesn't matter a whole lot, the main barrier to save games is making sure they're properly planned for. The two main things you need to do are make sure that save data can be handled as an actual island of data (i.e. you need to be able to reconstruct references, possibly circular ones, and you need to be able to store references to other subsystems like the renderer without traversing into those subsystems), and you may need to think about how you're going to handle version compatibility (i.e. storing a minimal set of checkpoint-anchored data is usually easy to make in a way that survives game updates, but frozen world states with actual objects in them are not).

One thing to watch out for with JSON and XML is that both of them are hierarchical formats, so they don't really like circular references. There are things you can do with IDs in XML, but it's not entirely straightforward.

OneEightHundred fucked around with this message at 15:46 on Mar 27, 2013

Chunderstorm
May 9, 2010


legs crossed like a buddhist
smokin' buddha
angry tuna
So I'm having a problem setting up a JRPG-type battle system in Unity. Basically, I declared each of my GameObjects and linked them to the appropriate GameObjects in the inspector. Then I loaded them into my battleParticipantsUnsorted array. Whenever I get to the foreach loop, though, it returns a null reference exception, and I can't figure out why.

My comments are overdone because this is for a class project, and all of us are designers rather than programmers. This is my first time trying to do something big in Unity. Please be gentle. :ohdear:

code:
	public GameObject ally1; // ally1 is ALWAYS the player
	public GameObject ally2;
	public GameObject ally3;
	public GameObject ally4;
	
	public GameObject enemy1;
	public GameObject enemy2;
	public GameObject enemy3;
	public GameObject enemy4;
	
	private int numberOfBattlers = 0; // how many people are battling?
	private int turnOrderCounter = 0; // used for checking whose turn it is
	private int currentTurn = 0; // current turn
	private int tempHighSpeed = 0; // used for turn order
	
	private GameObject[] battleParticipantsUnsorted = new GameObject[8]; // unsorted array of ally1-4 and enemy1-4
	public GameObject[] battleParticipants = new GameObject[8]; // array gets sorted later for turn order
	
	// Use this for initialization
	void Start () {
		
		// there needs to be a function here that assigns allies and enemies a value from an external script
		// will be implemented once the overworld and battles are integrated
		
		//load each battle participant
		battleParticipantsUnsorted[0] = ally1;
		battleParticipantsUnsorted[1] = ally2;
		battleParticipantsUnsorted[2] = ally3;
		battleParticipantsUnsorted[3] = ally4;
		battleParticipantsUnsorted[4] = enemy1;
		battleParticipantsUnsorted[5] = enemy2;
		battleParticipantsUnsorted[6] = enemy3;
		battleParticipantsUnsorted[7] = enemy4;
		
		// figures out how many participants there are in battle
		foreach (GameObject g in battleParticipantsUnsorted)
		{
			statHolder s; //script variable, statHolder is the type, s is the name
        		s = g.GetComponent("statHolder.cs") as statHolder; // gets the script from the current game object
			if (s.speed != 0)
			{
				numberOfBattlers++;
			}
		}
		
		// determine turn order
		GetTurnOrder();
		
		// call first turn after determining turn order
		InitiateTurn();
	
	}

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

HarkToTheLoons posted:

So I'm having a problem setting up a JRPG-type battle system in Unity. Basically, I declared each of my GameObjects and linked them to the appropriate GameObjects in the inspector. Then I loaded them into my battleParticipantsUnsorted array. Whenever I get to the foreach loop, though, it returns a null reference exception, and I can't figure out why.
It looks okay to me - I'd suggest putting a breakpoint on the 'foreach' line, then opening all the suspect variables in the inspector to see what's in them. I think mouseovering variables when stopped at a breakpoint shows what they are too, but I'm not sure, I've been using other environments recently.

vvvv Ahh, I didn't check that far because he said "when I get to the foreach loop" not "a couple of lines into the foreach loop". Using the debugger and a breakpoint would have helped find the problem anyway though, teaching a man to fish and all that. I think in js you're still supposed to cast a GetComponent return value, and in C# you'd use a template GetComponent<scriptname>()

roomforthetuna fucked around with this message at 20:50 on Mar 27, 2013

Torch Dexter
Dec 3, 2006

HarkToTheLoons posted:

code:
       s = g.GetComponent("statHolder.cs") as statHolder; // gets the script from the current game object

Assuming everything else is correct - this would be your problem. Usually I'd pass the Type of the object to GetComponent() - until I went and checked the Unity documentation just now I didn't know you could pass it a script name in a string instead. Anyway - if passing a string as the parameter you should drop the .cs from the end and it seems it should work.

To be honest though, you should probably just pass the type of the object - and then the cast would be unnecessary.

so:

code:
	s = g.GetComponent<statHolder>();
		or
	s = g.GetComponent("statHolder") as statHolder;
Edit: Whoops - Corrected for C# Syntax instead of original JS

Torch Dexter fucked around with this message at 20:55 on Mar 27, 2013

SlightlyMadman
Jan 14, 2005

I got the game dev bug again, and I decided it was time to learn Unity, since my pygame projects always end up hitting a performance wall as soon as they really get going, particular due to the language's lack of proper threading.

I went through a fun little tutorial where I made a clock and it looks pretty cool, but I just wanted to make sure I'm not headed down completely the wrong path before I spend a lot of time with it. I'm only creating objects and things by hand in the GUI right now because it's there to help beginners, right?

Once I really learn how to use the environment, I hope to be able to do everything dynamically in code. I don't want to have to create each entity by hand that I might need in the game, but should be able to just create them out in code as I need them.

The main thing I'm hoping to leverage here is an easy to use 3D environment, since I've only ever done 2D games in the past. For the moment, it's basically just going to be a flat plane with different sized blocks on it.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
My (C#) game engine uses Lua scripts for all game logic. I am considering switching to C# scripting for a number of reasons. Does anyone have any good (preferably highly technical) articles on how Unity does this? I have an idea on how to go about accomplishing what I need (aggregate all scripts and use CSharpCodeCompiler to dynamically generate an assembly) but I want to see if there's any gotchas or concepts that I haven't considered yet.

Edit: For anyone who might be interested, here's my reasons for switching from Lua to C#: Better libraries (.NET), better IDE, no cross-language datatype conversions necessary (since the engine is in C#), better memory management (LuaInterface is kind of flaky), better performance, better debugging (this is a big deal).

Orzo fucked around with this message at 22:01 on Mar 27, 2013

Unormal
Nov 16, 2004

Mod sass? This evening?! But the cakes aren't ready! THE CAKES!
Fun Shoe

SlightlyMadman posted:

I got the game dev bug again, and I decided it was time to learn Unity, since my pygame projects always end up hitting a performance wall as soon as they really get going, particular due to the language's lack of proper threading.

I went through a fun little tutorial where I made a clock and it looks pretty cool, but I just wanted to make sure I'm not headed down completely the wrong path before I spend a lot of time with it. I'm only creating objects and things by hand in the GUI right now because it's there to help beginners, right?

Once I really learn how to use the environment, I hope to be able to do everything dynamically in code. I don't want to have to create each entity by hand that I might need in the game, but should be able to just create them out in code as I need them.

The main thing I'm hoping to leverage here is an easy to use 3D environment, since I've only ever done 2D games in the past. For the moment, it's basically just going to be a flat plane with different sized blocks on it.

It depends on the game you're trying to create; in some cases the unity editor is really useful, like creating a big scripted level for an RPG or adventure game. However there's nothing stopping you from doing everything programatically, and a lot of people like Futile, which is a completely programatic.

My games are almost entirely instantiated in code, with each scene typically only having a camera and a manager object with a "manager" script. It's quite straightforward once you get used to it, I'd dive right in.

Orzo I have no articles, but yay for runtime-compiled C#, I think you're going to be happy with the results. I've never read a technical article on doing it, but I've done runtime-compiled C# scripting for several projects, both hobby and commercial (with millions of installs, without any significant hiccups). I find it quite straightforward to just compile the scripts into an assembly or application domain (depending on the scope of the script) and reflect into it. I'd be happy to see any good articles you dig up on approaches, since I typically just get-it-done without a lot of finesse.

Unormal fucked around with this message at 22:31 on Mar 27, 2013

SlightlyMadman
Jan 14, 2005

Cool, I'm thinking of putting together a city sim, like probably several thousand other hobbyist programmers are doing right now, to try to scratch the itch that SimCity completely failed to even get near.

I figured Unity will make it easy to just put together a 3D world with camera and everything, and I can start by just representing the buildings as different sized blocks, and maybe skin them later. Of course the buildings need to be created and grown dynamically in-game, so I wanted to make sure that was possible.

I'll keep going through the tutorials and hopefully it will become clear.

Unormal
Nov 16, 2004

Mod sass? This evening?! But the cakes aren't ready! THE CAKES!
Fun Shoe

SlightlyMadman posted:

Cool, I'm thinking of putting together a city sim, like probably several thousand other hobbyist programmers are doing right now, to try to scratch the itch that SimCity completely failed to even get near.

I figured Unity will make it easy to just put together a 3D world with camera and everything, and I can start by just representing the buildings as different sized blocks, and maybe skin them later. Of course the buildings need to be created and grown dynamically in-game, so I wanted to make sure that was possible.

I'll keep going through the tutorials and hopefully it will become clear.

Well, for example, click any object in the editor. The entries like "Transform" and "Camera" down the inspector for that object are just "component" classes that have been added to that object; and the fields are usually simple reflection on the properties of those component classes. You could create an exactly-behaving copy for an object with a particular set of compoennts (in this case, for pure example, Physics and Whatever1, Whatever2, etc...) by going something like:

GameObject G = new GameObject();
G.AddComponent<Physics>();
G.GetComponent<Physics>().PropertyWhatever = blah blah;
...
G.AddCompoennt<Whatever1..n>();
G.GetComponent<Whatever1..n>().Property1..n = blah blah;
...
etc

There's nothing magic going on in the editor. Once you make that leap, and realize you can just add/remove components very easily willy-nilly in code and it mostly just works, you've pretty much understood how the core of Unity works. All the actual behavior for any particular object just comes from the behavior/event-responses of whatever components it happens to have, and can be changed on the fly by adding/removing/modifying components of those objects.

Adbot
ADBOT LOVES YOU

SlightlyMadman
Jan 14, 2005

Ah thank you! That's exactly what I was hoping to hear.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply