• Unity3D - Discussion
    5,004 replies, posted
[QUOTE=cam64DD;46008385]Oh I see! So that's what source games do to compensate for lag? They just do all the raycasting against older frames? Huh. That explains why shotguns and hitscan weapons on TF2 don't feel laggy, yet projectile-based weapons have this noticeable delay on servers with a high latency.[/QUOTE] Exactly. Basically, the client sends a shoot command to the server, and the server receives that message some time later (due to internet latency). The server basically then says "ok, so I know when the client sent this message, and I know what time it is now, so I can rewind the whole game by that much and THEN perform the hitscan, then restore the state of the game to normal" so that it raycasts against the world [I]as the client saw it when it sent the shoot message.[/I] It does [B]not [/B]do any latency compensation for projectile weapons, however. Bolt does pretty much all of this behind the scenes, so you just have to pass frame number to raycast against.
Guys, i'm making a simple top-down MMORPG which implies a single master server. I've done this before, but not with Unity and there's this Unity Networking thing. Should i just disregard it and do what i normally do in .NET? TcpClient, TcpListener and all that cool stuff?
Unity networking is terrible. Full stop.
[img_thumb]https://dl.dropboxusercontent.com/u/107588088/TimerDemo.png[/img_thumb] Finally added a timer; shows up as soon as you reach the surface, so you have a limited amount of time to build up your defences and do all the puzzles that give you neat advantages. Alongside that, I've hooked some GUI stuff into the code (at last the oxygen UI panel actually reflects the amount of oxygen there is - fades between red and green depending on the 02 percentage. Tomorrow is the day for making it effect the player). Added more factory stuff so you can actually make turrets and signal emitters and many things like that. Oh, and did more fancy effect stuff. You'll find out what if you play it.
Yeeeeellow! Coming around to try around Unity for the (n+1)th time and this time I finally kept going until things started making sense. Wrote a little snippet to "higlight"/outline any items that are interactable. [t]http://i.imgur.com/J1VIZF0.png[/t] [url=http://pastebin.com/WpNJe2RL]Source[/url], if anyone wants to take a peek. I basicly only have to do this [code] public class Item : MonoBehaviour, IInteractable { ... // Set the _modelRenderer somewhere, i.e. when spawning a prop etc. ... private Renderer _modelRenderer; #region Nested: IInteractable public Renderer ModelRenderer { get { return _modelRenderer; } } public Color OutlineColor { get { return new Color(1.0f, .5f, 0); } // Orange! } public void Highlight(GameObject go) { } public void Interact(GameObject go) { print("Pew pew interact " + go.name); } #endregion } [/code] It's not much, but feels like an achievement. Next up is my inventory system. Previously I've used AssetPreview.GetAssetPreview to generate a preview/2d image of all my 3d model prefabs - but this is pretty unreliable. Do you guys know of another way to do this?
Anyone know how bad the performance hit is to add/remove components on an object during play?
I don't know the exact figures, it's probably fine to do once in a while. If you're REALLY concerned and you're actually having performance issues, remember one of the golden rules of optimization: measure measure measure.
[QUOTE=Kidd;46027321]Anyone know how bad the performance hit is to add/remove components on an object during play?[/QUOTE] Could consider adding the all the components and enable/disable them as needed? I don't know if that makes sense in your situation.
Today I revisited my game. A certain minigame in there had its flow controlled by a bunch of booleans. I wanted to make a change to it, and I came back after 2 months and had no idea what the fuck was going on. So I learned about coroutines, since it's all GUI driven stuff. And it's now a chain of coroutines instead of a bunch of booleans. I am very happy.
[QUOTE=foszor;46027596]Could consider adding the all the components and enable/disable them as needed? I don't know if that makes sense in your situation.[/QUOTE] Trying to figure out the best way to add/remove functionality of an item. So I was thinking of the player gets a sword and modifies it to have something like fire damage applied to it, I thought maybe when that happens I'll tell it to apply a "Elemental Damage" script to the object and set the variables and what not in that to do fire stuff like igniting and whatnot. That is just an example, but could be any kind of functionality.
Hey guys, so I'm coming from a [URL="www.cardigangame.com"]rudimentary actionscript/Flash background[/URL] and I'm trying to get into Unity. Would it be cool if I asked all sorts of noob questions about Unity and C# here, or is this thread more for higher level stuff?
[QUOTE=Kidd;46028216]Trying to figure out the best way to add/remove functionality of an item. So I was thinking of the player gets a sword and modifies it to have something like fire damage applied to it, I thought maybe when that happens I'll tell it to apply a "Elemental Damage" script to the object and set the variables and what not in that to do fire stuff like igniting and whatnot. That is just an example, but could be any kind of functionality.[/QUOTE] Maybe you could have one component that handles all damage types. Pass the damage information in a struct with a bitwise flag that holds which type(s) of element(s) are in the attack and use an interface to create different delegates for each type. Using that approach you could have multiple elements in a single attack and each one could have their own particle effect and whatnot.
[QUOTE=Maloof?;46028246]Hey guys, so I'm coming from a [URL="www.cardigangame.com"]rudimentary actionscript/Flash background[/URL] and I'm trying to get into Unity. Would it be cool if I asked all sorts of noob questions about Unity and C# here, or is this thread more for higher level stuff?[/QUOTE] yep, that's cool.
What would be a good way of packaging my internal level files so they're difficult to edit? If I have them as TextAsset resources, you can open the resources.asset file in notepad and change the level code.
Why do you not want them modified? You could always encrypt the level data somehow...
Watching the Oculus Connect keynote. They just announced that Unity 5 will have a build target for the Oculus Rift. The modules will be native so you can now build VR games with the free version! [B]Edit:[/B] Statement from Unity: [url]http://blogs.unity3d.com/2014/09/20/expanded-oculus-rift-support-in-unity/[/url] [quote]The Oculus add-on will include stereo imaging optimizations, 3D audio support, deeper Unity editor integration, inclusion of the Oculus Rift in the Unity development and debugging workflow, integration of Oculus-specific APIs within Unity, and direct publishing to the Oculus platform.[/quote]
[QUOTE=Pelf;46031805]What would be a good way of packaging my internal level files so they're difficult to edit? If I have them as TextAsset resources, you can open the resources.asset file in notepad and change the level code.[/QUOTE] What format are they in right now? JSON? [editline]20th September 2014[/editline] The reason I ask, if you used System.IO.BinaryWriter you could 'compile' whatever text based format into a binary format. Then, use the .bytes file extension as describe in the [url=http://docs.unity3d.com/Manual/class-TextAsset.html]Text Asset[/url] documentation to read the binary information to load your levels.
[QUOTE=Pelf;46030462]yep, that's cool.[/QUOTE] Cheers! I guess the most pressing question I have now (and one that I didn't run into when I was using AS3) is the unusual use of unusual objects, esp. when dealing with prefabs. The tutorial I'm doing at the moment has me using a script to create a bunch of prefab boxes and alter their locations. Instead of creating and instantiating the boxes then accessing and messing with their coordinates (box.x + distancetobemoved), the tutorial has this: [code]public Transform prefab;[/code], and we then assign our prefab object to that. I don't understand how 'Transform' can be an object. Does this all mean that we're telling our code to only access and mess with the transform information of the prefab instead of the entire prefab object for efficiency's sake?
Well, Transform isn't an object. An object [I]has[/I] a Transform. That's basically a shortcut - you can drop the box prefab onto the slot in the inspector, and then from code you can access the Transform attached to that prefab. So while you could [code] public GameObject prefab; // later prefab.transform.position += whatever; // <- note the .transform [/code] You can also do [code] public Transform prefab; // later prefab.position += whatever; // <- .transform omitted [/code] It can be more efficient, but not in the way you're describing. Basically, this: [code] prefab.transform [/code] Can [I]potentially[/I] be a little slow, as it seems to boil down to: [code] prefab.GetComponent<Transform>(); [/code] So having access to the transform directly could be a little faster.
-snip- answered above
Also, I guess Instantiate(transform) just instantiates the whole object, as if you had done Instantiate(gameObject)? Probably, under the hood, they're doing something like: [code] public Object Instantiate( Object obj ) { if( obj is Transform ) { return Instantiate( obj.gameObject ); } // snip } [/code]
So I've made a little hostage system. [vid]http://s1.webmshare.com/o87mv.webm[/vid] Basically what it shows is if you point your weapon at a civilian you fill up their intimidation bar (red circles). When you're intimidating a hostage, you have the ability to control said hostage until the intimidation runs out. You can control the hostage for as long as you want if you keep them in gun sights. Currently they don't do anything if the intimidation runs out, but I'll be making it so they start legging it for the exit / for help.
[QUOTE=KillaMaaki;46035045]Well, Transform isn't an object. An object [I]has[/I] a Transform. That's basically a shortcut - you can drop the box prefab onto the slot in the inspector, and then from code you can access the Transform attached to that prefab. So while you could [code] public GameObject prefab; // later prefab.transform.position += whatever; // <- note the .transform [/code] You can also do [code] public Transform prefab; // later prefab.position += whatever; // <- .transform omitted [/code] It can be more efficient, but not in the way you're describing. Basically, this: [code] prefab.transform [/code] Can [I]potentially[/I] be a little slow, as it seems to boil down to: [code] prefab.GetComponent<Transform>(); [/code] So having access to the transform directly could be a little faster.[/QUOTE] Oh I understand! Yup, I knew that .transform was a function we could call in the prefab, but I didn't know we could access it more simply and directly by calling it when we create it (sorry, not sure what the technical name is for creating an object in code without creating an instance at the same time). So we're essentially jumping down the prefab object's tree so that any function call we make is automatically assumed to be a transform function call. Does this also mean that if we wanted to alter functions of the prefab that [I]weren't[/I] related to transform functions, we'd have to rethink our object creation and instead create the prefab directly as a gameObject?
Every component has a .gameObject property which points to the game object it is attached to (including transform). EDIT In case it helps, I'll see if I can express some of these concepts in AS3-style code. So let's say you've got the Component class. [code] public class Component { // the game object this component is attached to public var gameObject : GameObject; } [/code] You've also got the GameObject class, which holds a bunch of components. [code] public class GameObject { // the components attached to this game object private var _components : Array; public function GetComponent( compType : string ) : Component { // find and return a component from the _components array of the given type } public static function Instantiate( sourceObj : GameObject ) : GameObject { // make a copy of sourceObj, add it to the scene, and return the copy } } [/code] So then there's the Transform component: [code] public class Transform extends Component { public var position : Vector3; public var rotation : Quaternion; public var scale : Vector3; } [/code] Then the GameObject basically has a shortcut for accessing the transform attached to it, as a [B]property[/B]. You may know these in AS3 as implicit getter/setters (the get and set keywords for functions): [code] // the transform attached to this game object public function get transform() : Transform { return GetComponent( "Transform" ) as Transform; } [/code] But then there's that thing with Instantiate, where instantiating the transform actually copies the whole game object. That's likely handled as a special case in the Instantiate function, and probably looks like this: [code] public static function Instantiate( sourceObj : Transform ) : Transform { // first clones the game object, then returns the transform of the new clone return Instantiate( sourceObj.gameObject ).transform; } [/code] Does that make sense? Apologies if I made any blatant AS3 mistakes - my AS3 is very rusty, I'm primarily a C# developer.
Yeah, Ok [IMG]https://dl.dropboxusercontent.com/u/33714868/arrows.gif[/IMG]
I'm messing about with the 4.6 GUI system. Can't seem to get it to get Raycasts to hit it despite it being in the mask, so the scene behind the UI is being changed? Is there something I need to check or what? Nevermind, sorted by checking if this game back true or false: [code]EventSystemManager.currentSystem.IsPointerOverEventSystemObject(-1)[/code]
I'm trying to implement lua inside my game, and also...Autoreload, i'm using FileSystemWatcher...But when i reload the file i get an exception: [lua]get_dataPath can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.[/lua] Seems like event handle run on another thread...When i tried to fix it by removing the Application.appData dependence i just found that nothing it's reloading because i'm still running on another thread...There's a way to run in unity again a function (With a parameter) in the main thread?
[QUOTE=gonzalolog;46039539]I'm trying to implement lua inside my game, and also...Autoreload, i'm using FileSystemWatcher...But when i reload the file i get an exception: [lua]get_dataPath can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.[/lua] Seems like event handle run on another thread...When i tried to fix it by removing the Application.appData dependence i just found that nothing it's reloading because i'm still running on another thread...There's a way to run in unity again a function (With a parameter) in the main thread?[/QUOTE] What I do is have a queue of items to process. The item in this case could just be a string containing the filename of the file to reload. When I get file change event (on a worker thread), lock a sync root and enter the changed file into the queue. In an Update method of a component somewhere, on the main thread, I lock the sync root and check the queue for items - if there are items waiting, dequeue until empty and reload there.
Well, I think I have a very unique problem. Most people complain about spikes of low framerate - I appear to be having the exact opposite! Spikes of VERY high framerates - 300 or more - even though vsync is enabled! It's screwing up my mouse look. Seems to be mostly an issue in DX11. WTF. [editline]21st September 2014[/editline] The mystery deepens. - I noticed the lag... uh, spikes? dips? I dunno what to call them - were related to mouse movement! When I left the mouse alone, no dips. Moving the mouse - dips. - That's when I remembered, my Wacom tablet is plugged in. So I unplugged it. Framerate dips/spikes/whatever went away. WTF? So lesson learned, I guess? Unity is allergic to Wacom tablets? EDIT Anyway, current progress on FPS kit. - Added multiple weapons, added SMG to loadout. - Changed how UI works, it's now more modular (different pieces of the UI are separate prefabs) - Added scoreboard which shows name, kills, and deaths of each player. [video=youtube;XEQuFC7zTxw]http://www.youtube.com/watch?v=XEQuFC7zTxw[/video]
does unity have anything like a SFML SoundStream which allows you to handle streaming of audio directly, passing the chunks of audio yourself (so I can do shit like bitcrushing at runtime)
Sorry, you need to Log In to post a reply to this thread.