Author Topic: Shrugger! Unity!  (Read 39140 times)

Offline Shrugging Khan

  • Hero Member Mark III
  • *****
  • Posts: 1,216
  • Neinzul Y PzKpfw Tiger!
Shrugger! Unity!
« on: July 28, 2013, 10:16:37 AM »
So now that I've more or less survived my first few months of computer science, I thought I'd make a little game to motivate me for the coming second term.

"Let's make a sandbox exploration game", thought me, and realised that I didn't have the tech savvy to make it playable.
"How about a physics-based RTS?", suggested another part of my brain. Yeah, physics, that's complicated stuff.
"An FPS about natural selection and tactics?" - Dear Lord, no, we'd need really good AI to make it worth it.
"A space 4x with realistic scale!", was a thought. "Wait, mathematics and such? Relativistic physics? Ha ha ha!", was another.

And after a few weeks, yet another idea cropped up.

"A 3D roguelike?", I asked myself, and failed to think of any reason why that'd be too hard. So I fired up unity, imported some standard assets, and immediately started bludgeoning my desk in fury.

"Y u no multidimensional arrays, javascript!?", I raged. "You there, GameObject! How hard can it be to have a simple color instead of shaders and textures and god knows what?", I interrogated Unity. "WHY HAVE YOU STOPPED WORKING, SCRIPT!?", shouted I, my hands searching in vain for a throat to strangle - all I had done was rearrange a few folders.

In short, I am a complete and utter idiot. And I have many questions.
The first shall be this:

1. Issue One: Multidimensional Arrays, or alternatives thereto

I want to create a three-dimensional level to play in, using simple cubes. I thought it'd be fun to write an algorithm to plan the level, with multiple floors, rooms, staircases, corridors and whatnot. The plan was to store the layout in a matrix; or perhaps rather to have the matrix represent the level, with three dimensions denoting coordinates, and each element containing information regarding block type, structural integrity, temperature or whatnot.

Alas, my meagre coding experience did not suffice. I didn't even manage to make the bloody matrix happen! So, how can I create a simple array with three or five or eight or perhaps a dozen dimensions to store my level map in? How can store further arrays within this array?

Or is there a simpler, perhaps a simply better way to do it?
My guess is there's some object-oriented solution I'm not thinking of, or some other way of making such a map happen. Not that I'd actually know - as mentioned above, I am an idiot.

So, if anyone can make sense of all this, and perhaps provide some insight...I'd be much obliged!
The beatings shall continue
until morale improves!

Offline x4000

  • Chris Park, Arcen Games Founder and Lead Designer
  • Administrator
  • Zenith Council Member Mark III
  • *****
  • Posts: 30,647
Re: Shrugger! Unity!
« Reply #1 on: July 28, 2013, 01:38:50 PM »
First suggestion: use C#. Everything is more vague in JavaScript, I feel like. Speaking as one who used js moderately heavily for 8 years in a web environment.

In c# you can do multidimensional arrays with new object[][]. In JavaScript the only way I know to do it is something like new Array( new Array() ). Etc.  In c# you can also do new object[,]. Those are all two dimensional arrays, but for three it's the same.

I can't help you much with gameobjects or 3d in unity, though, because we use drawmesh and drawmeshnow (pro features) along with custom textured quads out of vertex arrays. We obviously do use shaders, but nothing all that complex and we mostly use them by setting the current material directly or by using materialpropertyblocks (or whatever those are called, it's been a while since all that is long-since wrappers a by our own code.

We only even use a single script, very short, attached to the camera. Everything else is custom class-based code elsewhere in the codebase that the script invokes once per frame.

Anyway, so we're of limited help on traditional unity things, just to warn you.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark IV
  • *****
  • Posts: 3,905
Re: Shrugger! Unity!
« Reply #2 on: July 28, 2013, 06:05:56 PM »
This rant may provide if not insight, then sympathy.

That said, Unity is really difficult to work with in some ways, but really awesome in other ways.

What version are you working with, 3.5, 4?

One thing to avoid: OnGUI.  Do not use the built-in GUI tools, it will only end poorly.  Either spend the money on a gui package (like iGUI*) or use an orthogonal camera and 2D planes and mesh-text.

Shaders: you can probably get away with the various supplied shaders and freely available shaders out there if you're doing something like a dungeon crawling roguelike.  You aren't doing anything that would require rim lightning or translucency or subsurface scattering.  You need rocks.

*Note: I don't like iGUI much, but it's still better than native and not that expensive.

Offline x4000

  • Chris Park, Arcen Games Founder and Lead Designer
  • Administrator
  • Zenith Council Member Mark III
  • *****
  • Posts: 30,647
Re: Shrugger! Unity!
« Reply #3 on: July 28, 2013, 07:43:15 PM »
The only thing that I use OnGUI for is for textboxes/textareas.  If anyone knows of a third party solution that provides sprite-based support for those, I'll be all over it because that's the last piece that we have not been able to ditch.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark IV
  • *****
  • Posts: 3,905
Re: Shrugger! Unity!
« Reply #4 on: July 28, 2013, 08:03:31 PM »
The only thing that I use OnGUI for is for textboxes/textareas.  If anyone knows of a third party solution that provides sprite-based support for those, I'll be all over it because that's the last piece that we have not been able to ditch.

How's $10 sound? ;D

Offline x4000

  • Chris Park, Arcen Games Founder and Lead Designer
  • Administrator
  • Zenith Council Member Mark III
  • *****
  • Posts: 30,647
Re: Shrugger! Unity!
« Reply #5 on: July 28, 2013, 08:05:59 PM »
That's not a textbox or a text area, that's just a label -- we already have something quite robots, even beyond what you've got there.  A textbox is like the subject field on this page, whereas the text area is like the body.  Those are extremely hard to program in any language (I've done it before, and it was kind of buggy, and it was extremely hard to do).
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark IV
  • *****
  • Posts: 3,905
Re: Shrugger! Unity!
« Reply #6 on: July 28, 2013, 08:46:10 PM »
That's not a textbox or a text area, that's just a label -- we already have something quite robots, even beyond what you've got there.  A textbox is like the subject field on this page, whereas the text area is like the body.  Those are extremely hard to program in any language (I've done it before, and it was kind of buggy, and it was extremely hard to do).

Cursory search, ah well.

Offline x4000

  • Chris Park, Arcen Games Founder and Lead Designer
  • Administrator
  • Zenith Council Member Mark III
  • *****
  • Posts: 30,647
Re: Shrugger! Unity!
« Reply #7 on: July 28, 2013, 08:47:53 PM »
No worries.  Believe me, I periodically scour for that. ;)
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Shrugging Khan

  • Hero Member Mark III
  • *****
  • Posts: 1,216
  • Neinzul Y PzKpfw Tiger!
Re: Shrugger! Unity!
« Reply #8 on: July 29, 2013, 08:37:57 AM »
Bah, no need for a GUI!

Still, thanks for the tips. Going to try a few things and report back later with more questions.
The beatings shall continue
until morale improves!

Offline Billick

  • Full Member Mark III
  • ***
  • Posts: 244
Re: Shrugger! Unity!
« Reply #9 on: July 29, 2013, 09:16:42 AM »
Is it possible to use any of the C#/.net/WPF GUI stuff together with Unity, or does that just not work?

Offline x4000

  • Chris Park, Arcen Games Founder and Lead Designer
  • Administrator
  • Zenith Council Member Mark III
  • *****
  • Posts: 30,647
Re: Shrugger! Unity!
« Reply #10 on: July 29, 2013, 09:35:19 AM »
Unity supports C# via mono, but you can't use something like wpf or windows forms -- those are not opengl/directx based (both run in software mode, not hardware-accelerated).
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Shrugging Khan

  • Hero Member Mark III
  • *****
  • Posts: 1,216
  • Neinzul Y PzKpfw Tiger!
Re: Shrugger! Unity!
« Reply #11 on: August 02, 2013, 04:19:28 PM »
Awwwright! So I now have working but horrifyingly inefficient procedural world generation (It generates a flat plain and a featureless tower, with semi-random colours. Go me!), and a day-night cycle with weird colours.
So far, so nothing at all yet. Questions!

1) I originally tried to make large structures out of uniform small cubes, but that quickly left me with over 10000 cubes to generate, and caused Unity to crash.
Now, I'm considering two options: Using larger gameObjects (pillars, walls, whole buildings) for all larger structures, with small blocks only where necessary, or using procedurally generated polygons instead of cubes (I don't even know if that's possible, or if I have the geometry skills for it).

Is there another way, perhaps, to simply increase the resource efficiency of the original, quasi-minecraft-style block system? Like only generating the world one area at a time rather than all at once, only rendering those cube faces facing the player (and within his FOV), or some obscure coding trick I'm not aware of?

2) I'm trying to instantiate a bunch of critters with AI scripts attached to them. This seems to be simple enough using addComponent to add the script, but I wonder if I should do it differently. Is this method good enough, or am I being an Idiot and there's much better ways to do it?

3) For things like creature attributes, NPC equipment and whatnot - what's the best way of storing that data? Right now I'm just using int[, , , , , ,] arrays, but I can't imagine that that's the best way to do it.
The same question applies to the previously mentioned world generation array, in which I store block coordinates and types. Is that even a good method?

4) What's the best way to write down things like enemy types, items, skills etc.? Just right there in the scripts, or maybe with something like XML files? I have no buggering idea how that even works, but it'd be nice to know what angle to aim for.
The beatings shall continue
until morale improves!

Offline x4000

  • Chris Park, Arcen Games Founder and Lead Designer
  • Administrator
  • Zenith Council Member Mark III
  • *****
  • Posts: 30,647
Re: Shrugger! Unity!
« Reply #12 on: August 02, 2013, 04:25:35 PM »
1. Yes, you just need to have a disconnect between how your world is generated versus how it is displayed.  IE, generate your cubes however you want, in terms of knowing what they are and where they are, but this is your own custom code and has nothing to do with Unity GameObjects or whatever.  Then whatever cubes are in the view, use reusable Unity GameObjects for those.  Depending on your draw distance, hopefully you're not seeing thousands of those.

2. No idea, never have used AI scripts or addComponent, sorry.

3. Object oriented programming with custom properties, for sure.  Or are you using Javascript?  I can't recall.  JS really is inferior for structured data...

4. Up to you, really.  Mostly we put it in the code because it's quick to do and quick to access, and we don't really want those things being externally changed.  But some things we do read in from external files, like particle effects or whatever.  It depends on the specific use case, honestly.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark IV
  • *****
  • Posts: 3,905
Re: Shrugger! Unity!
« Reply #13 on: August 02, 2013, 04:29:00 PM »
1) I originally tried to make large structures out of uniform small cubes, but that quickly left me with over 10000 cubes to generate, and caused Unity to crash.
Now, I'm considering two options: Using larger gameObjects (pillars, walls, whole buildings) for all larger structures, with small blocks only where necessary, or using procedurally generated polygons instead of cubes (I don't even know if that's possible, or if I have the geometry skills for it).

Separate your visuals from your procedurals.

Minecraft essentially has a 3 dimensional array of integers that it uses to hold the world information.  Each integer refers to a complex block class, which is instantiated once.

The visuals are a lot of rendered face, but only the visible ones.

Offline Shrugging Khan

  • Hero Member Mark III
  • *****
  • Posts: 1,216
  • Neinzul Y PzKpfw Tiger!
Re: Shrugger! Unity!
« Reply #14 on: August 03, 2013, 06:37:26 AM »
I'll have to get back to you about the visual/procedural issue (I get your points, but the actual way to do it eludes me still).

Regarding Object Oriented Programming for NPC attributes and the like, can anyone give me some basic pointers? My OOP-Fu is rather weak, I'll admit. It's my general failing, to rely too long on simple tools where more refined ones would be more appropriate...hence my using simple arrays instead of something sensible.

What do I need? Basic C# scripts, or a different format? Classes? Methods? Properties? All of that stuff is quite a mess in my head, so if someone could give me a brief overview of what is needed, I#d be much obliged.
The beatings shall continue
until morale improves!