• Unity3D - Discussion
    5,004 replies, posted
[QUOTE=acds;43522408]Yeah ideally it would be a full-fledged inventory. Also I am currently storing items in the inventory as GameObjects, but that was mostly a temporary thing, so now I'm thinking of how to do it. I assume a Item class with the needed variables is the way to go. How would I store what the item should become once I drop it and/or re-introduce it to the gameworld/scene though? If I store the GameObject in a variable, it feels like I might as well store the whole thing as a GameObject then.[/QUOTE] I've done something similar to this, though undoubtedly I did it in the most inefficient way possible. I also did it with Unity's 2D features, and I'm not sure what you're using, but I assume this could be extrapolated for use with 3D if you need it. One thing I've tried that sort-of solves the problem is to have a basic item component script with variables to control it's behaviour (such as if it is a weapon or armour, what it's damage or defence is, melee or projectile etc.). Slightly limiting in it's use, I know, but I suppose if you made a base component that other classes inherited from you would have more item customisation and still be able to do this next bit; Each item is set up from the basic script, and assigned to a prefab alongside it's sprite (which is then stored in the script itself). If the item is picked up, only the script is copied over to the player's collection of items, where it can be used to attack/defend or whatever (the GameObject is destroyed). If you need to assign items to the player or an NPC by default (without picking something up), you could assign these prefabs to their inventory directly from the editor's inspector (I believe it is possible to just attach one of a prefab's components to another object? If not, you could assign an instance of the prefab, destroy the GameObject and keep the item script (which would perhaps be more costly)). I then made a blank game object that has a sprite renderer attached to it (without sprite) and some basic 2D physics stuff (because I wanted my items to bounce around), which I assigned to a prefab. When the player drops the item, the prefab is instantiated and placed in the direction the player is facing. A blank item component is added to the new object, and the variables from the dropped item are assigned to it. The item script on the player is then destroyed. The newly placed item (with all the information of the previous one) sets it's sprite renderer to display the sprite in the script, making it exactly the same as the one that was picked up. I'm not sure what the overhead is for copying all the variables over (really, it depends on how many variables the script has), but when it is being stored it uses up less room because it's a single component that isn't attached to anything. I think. I'll be honest, I just sort of assumed that bit :v: Also, in case you or anyone else wants it, here is what I use for copying the fields over between different instances of the items (inventory -> world, etc). Again, I assume that it's the least efficient thing in the world, so I apologise for any crimes against humanity etc. etc. [code] ItemLogic transferItem = newGhost.AddComponent<ItemLogic>(); foreach(FieldInfo f in il.GetType().GetFields()) { f.SetValue(transferItem, f.GetValue(il)); } [/code]
[QUOTE=Jcorp;43522879]I've done something similar to this, though undoubtedly I did it in the most inefficient way possible. I also did it with Unity's 2D features, and I'm not sure what you're using, but I assume this could be extrapolated for use with 3D if you need it. One thing I've tried that sort-of solves the problem is to have a basic item component script with variables to control it's behaviour (such as if it is a weapon or armour, what it's damage or defence is, melee or projectile etc.). Slightly limiting in it's use, I know, but I suppose if you made a base component that other classes inherited from you would have more item customisation and still be able to do this next bit; Each item is set up from the basic script, and assigned to a prefab alongside it's sprite (which is then stored in the script itself). If the item is picked up, only the script is copied over to the player's collection of items, where it can be used to attack/defend or whatever (the GameObject is destroyed). If you need to assign items to the player or an NPC by default (without picking something up), you could assign these prefabs to their inventory directly from the editor's inspector (I believe it is possible to just attach one of a prefab's components to another object? If not, you could assign an instance of the prefab, destroy the GameObject and keep the item script (which would perhaps be more costly)). I then made a blank game object that has a sprite renderer attached to it (without sprite) and some basic 2D physics stuff (because I wanted my items to bounce around), which I assigned to a prefab. When the player drops the item, the prefab is instantiated and placed in the direction the player is facing. A blank item component is added to the new object, and the variables from the dropped item are assigned to it. The item script on the player is then destroyed. The newly placed item (with all the information of the previous one) sets it's sprite renderer to display the sprite in the script, making it exactly the same as the one that was picked up. I'm not sure what the overhead is for copying all the variables over (really, it depends on how many variables the script has), but when it is being stored it uses up less room because it's a single component that isn't attached to anything. I think. I'll be honest, I just sort of assumed that bit :v: Also, in case you or anyone else wants it, here is what I use for copying the fields over between different instances of the items (inventory -> world, etc). Again, I assume that it's the least efficient thing in the world, so I apologise for any crimes against humanity etc. etc. [code] ItemLogic transferItem = newGhost.AddComponent<ItemLogic>(); foreach(FieldInfo f in il.GetType().GetFields()) { f.SetValue(transferItem, f.GetValue(il)); } [/code][/QUOTE] Well I'm not an expert, but I think what you're doing is more efficient than what I'm doing. Right now I'm storing the GameObjects which have a script attached to them with the same name (so IronHelmet would have IronHelmet script attached) which store the variables. To read those variables in the script I have to do some acrobatics (access the script by using the name of the current element of the list attached to said element, as per MainInventory[x].GetComponent(MainInventory[x].name) as Component.var) which really feel like needless complexity (maybe they aren't, not sure).
Scripts that do not need to be attached to GameObjects are derived from [url=http://docs.unity3d.com/Documentation/ScriptReference/ScriptableObject.html]ScriptableObject[/url] rather than Monobehaviour. ScriptableObject is useful for serialization, though it can be confusing at first (and more or less you have to start writing scripts to extend Unity Editor). Search for tutorials on ScriptableObjects. Also video by Tim Cooper on ScriptableObject: [media]http://www.youtube.com/watch?v=MmUT0ljrHNc[/media]
[QUOTE=Acegikmo;43509004]Oh, hi, yes :) It was quite a long time ago I was hanging around here! I've been working on Shader Forge for the last 5 months (And sort of need to take a shower and shave) I've put up a website with lots of neat images and a node documentation etc.! -> [url]http://acegikmo.com/shaderforge/[/url] Also, .gifs: [img]http://www.acegikmo.com/shaderforge/images/Misc/Animated/shaderforge_tessellation.gif[/img][img]http://www.acegikmo.com/shaderforge/images/Misc/Animated/shaderforge_vertexanim.gif[/img] [img]http://www.acegikmo.com/shaderforge/images/Misc/Animated/shaderforge_multiinput.gif[/img][img]http://www.acegikmo.com/shaderforge/images/Misc/Animated/shaderforge_uvrespect.gif[/img][/QUOTE] That's awesome. How did you get the knot looking object to transform like that? Is that something a geometry shader can accomplish? I haven't messed with shaders yet, but I didn't know that was possible.
[QUOTE=Drak_Thing;43545246]That's awesome. How did you get the knot looking object to transform like that? Is that something a geometry shader can accomplish? I haven't messed with shaders yet, but I didn't know that was possible.[/QUOTE] Well, yes, but you don't need to do a geometry shader (that one isn't, for instance!). It's a vertex transformation over time, along the normals, with a wave traveling across the torus knot in UV space :)
I love when a seemly complex task turns out to be really simple cutscenes [vid]https://dl.dropboxusercontent.com/u/13781308/Videos/Cutscenes.mp4[/vid]
So, in the future, astronauts will say hello by saying aeiou?
Unity has added PS Vita support. Still requires a license. [url]http://blogs.unity3d.com/2014/01/15/playstation-vita-deployment-is-here/[/url]
So I'm going to try to actually do something with Unity this time around. I'm going to make a GUI that hopefully doesn't suck by creating my own buttons and my own skin. Menu first, then a "garage" environment that is loaded by the menu button. I can do this shit :v:
Been working on async scene transitions. Instead of initializing and setting up everything in every scene, you keep the camera and essential gameobjects persistent and just "add" the objects from the new scene. For example: MenuSetup loads everything needed for the menu and then you transition between the different scenes, which all just contain a single menu object. MenuSettingsVideo MenuSettingsAudio MenuSettingsGame MenuHome MenuCredits
I apologize if this has been discussed already, but what do people typically use for networking in their Unity games? I've used Lidgren a ton before and it's amazing, I'd be inclined to go back to it but I feel like there must be some better solutions out there, specifically tailored to Unity. Do we know what Rust uses?
[QUOTE=Xeon06;43557266]I apologize if this has been discussed already, but what do people typically use for networking in their Unity games? I've used Lidgren a ton before and it's amazing, I'd be inclined to go back to it but I feel like there must be some better solutions out there, specifically tailored to Unity. Do we know what Rust uses?[/QUOTE] Pretty sure Rust uses [URL="http://www.muchdifferent.com/?page=game-unitypark-products-ulink"]uLink[/URL].
There's an extensive list of networking solutions for Unity [url=https://docs.google.com/spreadsheet/ccc?key=0AjZV0SdoOTsPdFVGQWxUWW9Fdmk2RzNfa3hUZU90V1E&usp=drive_web#gid=0]here[/url].
iTween is useful as fuck. Now I have camera movement for cutscenes.
So since storing GameObjects is quite inefficient (also needless difficulty in accessing properties of them) in an inventory, would a database with all the items be a good idea? Script would read the name of the object in question, find it in the database, and there read all the variables. Biggest drawback I can see it that it has to search every time and the thing could get quite massive, depending on how many types of items there are. What would be the best way to do that? I've seen plenty of games using text files. A non-component script with a class for each item (so class M1Garand and in that all the vars) maybe would be faster and more organized though? [editline]16th January 2014[/editline] Actually now that I think about it, I need to have a script attached to all items to define their behavior anyway (which needs the variables all the time, so having them outside the script would just be a bother), so I might as well just store it all in the items component script then read from that one when the vars are needed.
More cutscenes: [vid]https://dl.dropboxusercontent.com/u/13781308/Videos/Cutscenes2.mp4[/vid] Same scene as before but now with; camera motion, camera zooming, audio, and skipping cutscenes with escape key. The two beeps are audio being played with the audio feature; can specify a volume scale (0-1); It works using a keyframing type system: [IMG]https://dl.dropboxusercontent.com/u/13781308/ShareX/2014-01/2014-01-16_18-45-15.png[/IMG] Two of the cutscene functions: [IMG]https://dl.dropboxusercontent.com/u/13781308/ShareX/2014-01/2014-01-16_18-57-17.png[/IMG]
What would be the best way to keep the weapon in line with the camera rotation while still keeping it in vision? (Like eg. quake :p) The setup i have is this: [img]http://i.imgur.com/wfYuLv1.png[/img] Now when the camera rotates, the weapon follows it. But for example, if you look down all the way, you can see under the weapon. I tried multiple ways, but they all produce the same-ish result. The only way it worked correctly is when i add a new camera with the Depth only clear flag and the culling mask to a culling mask only used by weapons, but it's hard to believe that that is the best way :f
[QUOTE=Arxae;43571037]The only way it worked correctly is when i add a new camera with the Depth only clear flag and the culling mask to a culling mask only used by weapons, but it's hard to believe that that is the best way :f[/QUOTE] If you don't want the weapon to clip through world scenery, this is what you want to do. Otherwise I would just try parenting the gun to the camera. It shouldn't require any scripting magic.
I illustrated my point better here The problem also occurs with the "exit" point i added to the gun (it's a placeholder :p) Don't mind the ray [img]http://i.imgur.com/I5H62mT.png[/img] The red line is how the weapon should line up with the camera. The blue line is how the exit point should line with the gun. If i look straight ahead, it's all nice and dandy. But as soon as i look up/down the alignment of it all just gets thrown out the window
[QUOTE=Pelf;43571208]If you don't want the weapon to clip through world scenery, this is what you want to do. Otherwise I would just try parenting the gun to the camera. It shouldn't require any scripting magic.[/QUOTE] I wonder how VR games will handle it, probably move the weapon away to avoid weird depth "cut outs".
[QUOTE=Arxae;43571317]I illustrated my point better here The problem also occurs with the "exit" point i added to the gun (it's a placeholder :p) Don't mind the ray [img]http://i.imgur.com/I5H62mT.png[/img] The red line is how the weapon should line up with the camera. The blue line is how the exit point should line with the gun. If i look straight ahead, it's all nice and dandy. But as soon as i look up/down the alignment of it all just gets thrown out the window[/QUOTE] I've had problems like that before. I forget how I fixed it. I'll look and try and find out what I did. [editline]17th January 2014[/editline] Can you post the code you're using to rotate the gun?
Atm i'm not using any code. But it was basically setting the rotation of the hold point to the rotation of the camera.
Trying parenting the gun directly to the camera: >Player ->Main Camera -->Test Gun
Still gives me the same result :(
I tried doing what I suggested with the standard first person controller and it worked. You must be having some script interaction that's making it behave abnormally. [img]https://dl.dropboxusercontent.com/u/13781308/ShareX/2014-01/2014-01-17_13-25-18.png[/img]
Unity is updating their standard asset, [url=https://www.assetstore.unity3d.com/#/content/14474]currently in beta state.[/url] It has first/third person physics-based controller and other interesting stuff.
This beta Standard asset is good stuff to learn more about Unity. Physics-based FPSController is only around 100 lines of code without whitespaces and comments. Utility scripts provided too. Third person controller requires animation with root motion and Mecanim though. Oh, the scripts are in C#.
Too bad I have to redownload unity for a few bugfixes that I don't even need in order to try it out :( They really need a patcher system of sorts so you don't have to redownload all of unity for an update. [editline]edit[/editline] Yay, 3 hours to download 4.3.3 [editline]edit[/editline] New standard assets are great! Especially the particle effects. Gonna have to customize some for my lander game.
Worked with those new standard assets and redid the particle effect for the lander exploding. [vid]https://dl.dropboxusercontent.com/u/13781308/Videos/Booms.mp4[/vid] I think the flash would fit better with missiles.
Looks much much better
Sorry, you need to Log In to post a reply to this thread.