1. Post #2641
    Gold Member
    Asgard's Avatar
    July 2010
    4,262 Posts
    Is there a reason why AnimationCurve.Evaluate returns a float but displays as "NaN" in the inspector?
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

  2. Post #2642
    How is a NaN float used then but not displayable?

  3. Post #2643
    Gold Member
    Asgard's Avatar
    July 2010
    4,262 Posts
    How is a NaN float used then but not displayable?
    It's not used. It means something somewhere went wrong, you tried to do an invalid operation on a float and it returned NaN. Could you share the code?

  4. Post #2644
    It's not used. It means something somewhere went wrong, you tried to do an invalid operation on a float and it returned NaN. Could you share the code?
    But I am using it. It's working great.

    Code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Locomotion : MonoBehaviour {
    
        [Header("Locomotion Max Values")]
        public float maxSpeed;
    
        public float maxForce; //Maximum turn force
    
        private float currentSpeed;
    
        [Header("Target")]
        public Transform targetPosition;
    
        public float distance;
    
        [Header("Current Values")]
        public AnimationCurve DistanceVersusSpeed;
    
        public Vector2 currentVel;
        public Vector2 desiredVel;
    
        private Transform trans;
        private Rigidbody2D rBody;
        private CircleCollider2D coll;
    
        private bool initialGot;
    
        // Use this for initialization
        void Start() {
            trans = transform;
            rBody = trans.GetComponent<Rigidbody2D>();
            coll = trans.GetComponent<CircleCollider2D>();
        }
    
        // Update is called once per frame
        void Update() {
            Seek( Camera.main.ScreenToWorldPoint( Input.mousePosition ) );
        }
    
        void Seek( Vector3 tar ) {
            desiredVel = tar - trans.position;
            currentVel = rBody.velocity;
    
            float initialDistance = 0;
    
            distance = Vector2.Distance( trans.position, tar );
    
            if( initialGot ) {
                currentSpeed = DistanceVersusSpeed.Evaluate( 1.0f - ( distance / initialDistance ) ) * maxSpeed;
                if( distance > currentSpeed )
                    desiredVel = desiredVel.normalized * currentSpeed;
            } else {
                initialDistance = distance;
                initialGot = true;
            }
    
            if( distance > coll.radius ) {
                rBody.velocity = Vector2.ClampMagnitude( desiredVel, maxSpeed );
                //rBody.AddForce( desiredVel, ForceMode2D.Force );
            } else {
                rBody.velocity = Vector2.zero;
            }
        }
    }
    OH GOD. I just realized my initialDistance is local. Woooooooow.

    BUT why did AnimationCurve.Evaluate work then? The movement was following the curve....

    Ok so it never was working. It was doing what I wanted my curve to look like so I thought it was right. Any curve was the same result but removed
    Code:
     if( distance > currentSpeed )
    and it uses the curve I give now.
    Reply With Quote Edit / Delete Reply Windows 10 Chrome United States Show Events Programming King Programming King x 2 (list)

  5. Post #2645
    Gold Member
    Asgard's Avatar
    July 2010
    4,262 Posts
    Here's a little trick if you need to test networking with multiple clients. Create a new folder that has the Assets and ProjectSettings as symbolic link. Then you can open the project multiple times and the changes you make will recompile for all the projects.

    Reply With Quote Edit / Delete Reply Windows 10 Chrome Netherlands Show Events Programming King Programming King x 4 (list)

  6. Post #2646
    atrblizzard's Avatar
    June 2010
    192 Posts
    What's a proper way to sync a Unity scene from a machine to another on the fly? I'm trying to set up a local connection between two computers that would have the scene, or even just a specific game object shared/synced on both ends.

    Basically want to have the level editing to be done on one machine while the other to receive it in playmode.
    Reply With Quote Edit / Delete Reply Windows 10 Edge Romania Show Events Optimistic Optimistic x 1 (list)

  7. Post #2647
    Gold Member
    Clavus's Avatar
    September 2009
    8,441 Posts
    What's a proper way to sync a Unity scene from a machine to another on the fly? I'm trying to set up a local connection between two computers that would have the scene, or even just a specific game object shared/synced on both ends.

    Basically want to have the level editing to be done on one machine while the other to receive it in playmode.
    Couldn't you do it similar to how Asgard described it above? Make a separate Unity project folder, symlink the assets and projectsettings folders from your original project, then share one of the projects as a network folder and open that on the 2nd computer? You''ll be prompted to reload the scene when it's edited on one machine though, so I don't know how on-the-fly you want it to be.

  8. Post #2648
    Gold Member
    Asgard's Avatar
    July 2010
    4,262 Posts

  9. Post #2649
    KillaMaaki's Avatar
    August 2013
    1,100 Posts
    More cloud rendering shit.



    A bunch of changes made:

    - Clouds are now an image effect for performance. A half-resolution cloud buffer is composited with the screen. Additionally, clouds are rendered at half of that (quarter resolution), using a hack where the half-res buffer is divided into blocks of 2x2 pixels and the quarter resolution buffer is used to update one pixel out of each of those blocks every frame. To reduce artifacts resulting from camera motion, the previous frame is temporally reprojected for the current frame, filling in missing data (like screen edges) using the quarter resolution buffer. The temporal update is 100% imperceptible for camera rotations. These optimizations gained a huge performance boost and allowed the quality to increase considerably, running between 64-128 raymarch samples per fragment at around 800 FPS (500 with a full post effect stack).

    - I tossed out ambient lighting entirely. It never made sense - ambient lighting is generally light which has bounced off of the environment, but that far off of the ground there's not much for light to bounce off of. Instead, clouds add an atmospheric haze factor based on ray distance and rayleigh scattering.

    - I fixed my "powder term" for better edge darkening (that is, a term used by the HZD team to describe how powdered sugar looks darker on the edges).

    - I added a new weather map texture. Red stores cloud coverage, green stores raincloud coverage, and eventually blue will store moisture (rain clouds will be darkened with moisture, as well as distant "rain fog" so you can watch rain roll in from the horizon plus overhead rain particles). This weather map does a significantly better job of producing distinct coherent cloud shapes than just a simple coverage factor, plus you can now basically paint in clouds into a texture (though I'd also like to have a compute shader which produces a texture that scrolls in random weather conditions over time).
    Reply With Quote Edit / Delete Reply Windows 10 Chrome United States Show Events Winner Winner x 5 (list)

  10. Post #2650
    atrblizzard's Avatar
    June 2010
    192 Posts
    Just tried Scene Fusion, forgot that I still have a valid license once the early beta has ended. Unfortunately it doesn't sync well for the current 2D prototype I'm working on, the tilemaps are missing, probably due to the experimental custom build I'm using.

    I only need to sync the tilemap data in the scene within two computers that could be received in play mode, something like JSON and node maybe would suffice it?

    Speaking of tilemaps, the upcoming preview got me very excited, should be out very soon, but the final version will only make it in 2017.2.

    Reply With Quote Edit / Delete Reply Windows 10 Edge Romania Show Events Winner Winner x 7Zing Zing x 1 (list)

  11. Post #2651
    atrblizzard's Avatar
    June 2010
    192 Posts
    Holy shit, speak of the devil. The new 2D Preview Release 4 is out already and I just mentioned it the other day.

    Just got to upgrade my small prototype to the latest version and as always, ton of broken stuff. For one, all the tilemap components were replaced as Video Players, all due to changes mentioned in the changelog.
    Good thing I already had a tool written to export them to JSON, so it was just a matter of parsing them back.

    Reply With Quote Edit / Delete Reply Windows 10 Edge Romania Show Events Programming King Programming King x 1 (list)

  12. Post #2652
    Gold Member
    sarge997's Avatar
    August 2008
    2,332 Posts
    Tilemap looks so freakin cool. Can't wait until it releases.

  13. Post #2653
    Gold Member
    gonzalolog's Avatar
    April 2011
    3,435 Posts
    Can somone link me at complete changelog for unity 2017? I think i found 2017.1 version

  14. Post #2654

    May 2016
    119 Posts
    Can somone link me at complete changelog for unity 2017? I think i found 2017.1 version
    https://garry.tv/2017/01/03/unity-2017-changelist/

  15. Post #2655
    Gold Member
    gonzalolog's Avatar
    April 2011
    3,435 Posts
    Code:
    Editor Dark Skin is the only skin
    Removed Javascript support
    Can load models, animations, shaders at runtime
    Steam is treated as a platform (includes Steam SDK)
    Coolbeans

  16. Post #2656
    Fourier's Avatar
    July 2014
    3,927 Posts
    Today I was on a kind of 'how to do big game startup' and one of the leaders said 'It's difficult to find people, who can do Unity3D, because it's kind of new programming language'..

    Fucking cringe..
    Reply With Quote Edit / Delete Reply Windows 10 Chrome Slovenia Show Events Funny Funny x 8 (list)

  17. Post #2657
    Everyone has a $1 title
    Skipcast's Avatar
    November 2008
    6,756 Posts
    Code:
    Editor Dark Skin is the only skin
    Removed Javascript support
    Can load models, animations, shaders at runtime
    Steam is treated as a platform (includes Steam SDK)
    Coolbeans
    If only

  18. Post #2658
    Gold Member
    Drury's Avatar
    April 2011
    12,607 Posts
    what's the amazing benefit of removing unityscript?

  19. Post #2659
    Gold Member
    jmazouri's Avatar
    May 2005
    1,587 Posts
    what's the amazing benefit of removing unityscript?
    Unityscript is a proprietary superset of Javascript, and still compiles to IL/runs under Mono. I'd much rather Unity continue to improve their C# apis, rather than worrying about the small subset of people who refuse to learn the arguably superior, and generally more powerful C# syntax.

    Plus, since Unity assets tend to be distributed as source code, it can be annoying if your project is primarily C# and a critical asset is Unityscript/vice-versa.

    If Unity insists on maintaining multiple languages, they should provide hooks for developers to integrate other languages in a more direct and performant manner - I'd much rather see Typescript than Unityscript, for example.
    Reply With Quote Edit / Delete Reply Windows 10 Chrome United States Show Events Agree Agree x 6 (list)

  20. Post #2660
    Fourier's Avatar
    July 2014
    3,927 Posts
    Or F# and maybe Python.

  21. Post #2661
    srobins's Avatar
    December 2014
    4,611 Posts
    From the other help thread:

    Does anyone know if/how it's possible to share data between kernels in a compute shader? I'd like to basically fill an array with data in one kernel and have it be read by another kernel afterwards. I feel like this ought to be possible but I don't know any way other than to send the data from kernel #1 to the CPU and then upload it to kernel #2 before dispatch.

  22. Post #2662
    Gold Member
    Asgard's Avatar
    July 2010
    4,262 Posts
    All the terrain tools in the asset store are aimed around procedural generation and realism. Does anyone know of a Unity asset that does what Unreal's Terrain tools and World Composition does? Heightmap importing, (most importantly) brush painting, world streaming (no bloated plugins like World Streamer or SECTR. I want something I don't even need to think about when working), spline modifiers.

  23. Post #2663

    July 2011
    255 Posts
    What's a good way to recreate the Source Engine's Input/Output system? I've created an in-game button (a physical button in 3D space, not a UI button), and given the player the ability to press it. I want the button's output to be as versatile as possible, capable of triggering any behaviour I need. Do I need to build such a system myself, from scratch? Or does Unity already have this functionality built in somewhere?

  24. Post #2664

    May 2016
    119 Posts
    What's a good way to recreate the Source Engine's Input/Output system? I've created an in-game button (a physical button in 3D space, not a UI button), and given the player the ability to press it. I want the button's output to be as versatile as possible, capable of triggering any behaviour I need. Do I need to build such a system myself, from scratch? Or does Unity already have this functionality built in somewhere?
    You probably have to be somewhat more specific than that. Depending on how "ability to press it" looks like, you can just have the button detect whether it was pressed and then execute anything you want?

  25. Post #2665
    DFC
    DFC's Avatar
    September 2011
    424 Posts
    What's a good way to recreate the Source Engine's Input/Output system? I've created an in-game button (a physical button in 3D space, not a UI button), and given the player the ability to press it. I want the button's output to be as versatile as possible, capable of triggering any behaviour I need. Do I need to build such a system myself, from scratch? Or does Unity already have this functionality built in somewhere?
    Here's how I would probably do it.
    Code:
    class EventListener : Monobehavior {
    	
    	public delegate void OnEventHandler(string event);
    
    	public event OnEventHandler OnEvent = {}; // Other objects can subscribe to this by providing an OnEventHandler function
    }
    
    class Button : Monobehavior {
    	
    	public EventListener eventListener;
    	public string event;
    
    	public void PressButton () {
    		eventListener.OnEvent(event);
    	}
    }
    
    // I kept the Door and EventListener classes separate (rather than making EventListener the base class and using inheritance) so that Door can inherit from whatever you like.
    [RequireComponent(typeof(EventListener))]
    class Door : Monobehavior {
    	
    	void Awake () {
    		GetComponent<EventListener>().OnEvent += this.MyOnEvent; // Whenever someone calls the EventListener's OnEvent event, MyOnEvent will be called
    	}
    
    	public void MyOnEvent (string event) {
    		if (event == "open") {
    			// open the door
    		} else if (event == "close") {
    			// close the door
    		}
    	}
    }
    I just typed this in sublime so it might be a bit off, but you get the idea.
    Reply With Quote Edit / Delete Reply Mac Chrome United States Show Events Useful Useful x 1 (list)

  26. Post #2666

    January 2011
    485 Posts
    Here's how I would probably do it.
    Code:
    class EventListener : Monobehavior {
    	
    	public delegate void OnEventHandler(string event);
    
    	public event OnEventHandler OnEvent = {}; // Other objects can subscribe to this by providing an OnEventHandler function
    }
    
    class Button : Monobehavior {
    	
    	public EventListener eventListener;
    	public string event;
    
    	public void PressButton () {
    		eventListener.OnEvent(event);
    	}
    }
    
    // I kept the Door and EventListener classes separate (rather than making EventListener the base class and using inheritance) so that Door can inherit from whatever you like.
    [RequireComponent(typeof(EventListener))]
    class Door : Monobehavior {
    	
    	void Awake () {
    		GetComponent<EventListener>().OnEvent += this.MyOnEvent; // Whenever someone calls the EventListener's OnEvent event, MyOnEvent will be called
    	}
    
    	public void MyOnEvent (string event) {
    		if (event == "open") {
    			// open the door
    		} else if (event == "close") {
    			// close the door
    		}
    	}
    }
    I just typed this in sublime so it might be a bit off, but you get the idea.
    I thought using events in Unity was bad for performance?

  27. Post #2667
    DFC
    DFC's Avatar
    September 2011
    424 Posts
    Unity's event system has a performance overhead, but using delegate events shouldn't cause any slow down.

  28. Post #2668
    KillaMaaki's Avatar
    August 2013
    1,100 Posts
    Bad for performance in what situation? Are we talking one-off style events or a per-frame thing? Because for one-off events you are never going to notice a slowdown with any event system (which is what it sounds like is being asked about, as for a button press in the example given).

    EDIT: Side note, more cloud rendering. This time it's a video :O


    I'm getting much closer to being able to package this thing up and get it released. Want to work on more weather stuff but it's getting close :D
    Reply With Quote Edit / Delete Reply Windows 10 Chrome United States Show Events Artistic Artistic x 4Programming King Programming King x 1Winner Winner x 1 (list)

  29. Post #2669
    secundus's Avatar
    December 2009
    1,038 Posts
    I'm not sure about delegate events, but by using UnityEvent like this:

    Code:
        // UnityUI onClick, onValueChanged uses this way too
    
        [System.Serializable]
        public class OnSomethingEvent : UnityEngine.Events.UnityEvent<string> { };
        
        public OnSomethingEvent onSomethingHappened;
    
        [System.Serializable]
        public class OnAnotherThingEvent : UnityEngine.Events.UnityEvent<int, string, float, bool> { };
    
        public OnAnotherThingEvent onAnotherThingHappened;
    makes your event serializable in Inspector, allowing you to add listeners like UnityUI:


    However, with UnityEvent you're limited to 4 args.
    Reply With Quote Edit / Delete Reply Windows 8.1 Chrome Malaysia Show Events Winner Winner x 1 (list)

  30. Post #2670
    Everyone has a $1 title
    Skipcast's Avatar
    November 2008
    6,756 Posts
    I'm not sure about delegate events, but by using UnityEvent like this:

    Code:
        // UnityUI onClick, onValueChanged uses this way too
    
        [System.Serializable]
        public class OnSomethingEvent : UnityEngine.Events.UnityEvent<string> { };
        
        public OnSomethingEvent onSomethingHappened;
    
        [System.Serializable]
        public class OnAnotherThingEvent : UnityEngine.Events.UnityEvent<int, string, float, bool> { };
    
        public OnAnotherThingEvent onAnotherThingHappened;
    makes your event serializable in Inspector, allowing you to add listeners like UnityUI:


    However, with UnityEvent you're limited to 4 args.
    If you need more than 4 you're probably better off with a class or struct
    Reply With Quote Edit / Delete Reply Windows 10 Chrome Sweden Show Events Agree Agree x 2 (list)

  31. Post #2671
    Gold Member
    Janooba's Avatar
    February 2008
    1,577 Posts
    Bad for performance in what situation? Are we talking one-off style events or a per-frame thing? Because for one-off events you are never going to notice a slowdown with any event system (which is what it sounds like is being asked about, as for a button press in the example given).

    EDIT: Side note, more cloud rendering. This time it's a video :O


    I'm getting much closer to being able to package this thing up and get it released. Want to work on more weather stuff but it's getting close :D
    I love it! Are you planning on having actual weather effects, such as rain, lightning, etc?

  32. Post #2672
    KillaMaaki's Avatar
    August 2013
    1,100 Posts
    I love it! Are you planning on having actual weather effects, such as rain, lightning, etc?
    Absolutely. Actually, one thing I'm trying to do is make a nicely generic sound and particle system. The idea is you provide curves to particle effects and sound volumes which control the particle system's emission for a variety of parameters (cloud cover, temperature, moisture, etc). So for example you could hook up temperature curves to your precipitation and have it basically crossfade over to a snow effect as temperature drops below the freezing point. I also want to hook up sun height in the sky (rather than time of day, since TOD isn't a terribly good indicator of dawn or sunset depending on the latitude/longitude values you enter), so that you could also hook up for example birdsong vs crickets or whatever other night sounds you wanted with relative ease (plus the scripts show off how to read those values, so you could use them as a reference for stuff like turning on lights at night or whatever).
    I also have a built-in lightning effect, it took some work to implement but you can set the position and intensity of a virtual point light which lights the clouds (I wanted lightning bolts to appear positional, rather than just artificially brightening the clouds).

    Also one of the features I'm happy with is that weather is basically designed as a continuous function of position, time, and climate. At the moment it uses camera position but want to make it so you can pass a custom position offset (for example, for open worlds). And climate is a struct which contains temperature range, moisture range, and cloud cover ranges. The idea is that you could interpolate between different climate values at different times of year, and/or in different areas of your world, and also because it's a continuous function of position and time, weather events are actually persistent. So you could theoretically follow a storm as it moves through the game world. It also means you can watch storms approach from the horizon XD

  33. Post #2673
    Gold Member
    Janooba's Avatar
    February 2008
    1,577 Posts
    It also means you can watch storms approach from the horizon XD
    That's the part I like most about this whole thing. Watching an impending storm roll in is something you don't really see often in games, and could really add to the atmosphere, especially in a survival game where riding through a storm might need preparing.

  34. Post #2674

    July 2011
    255 Posts
    I appreciate the help from you all, but in asking my button question, I realised that I don't know as much about C# as I should, specifically what delegates are and how they work. I've got some reading material to cover that though, so I'll go over that on my own.

    I would like to ask if anyone here knows of any good documentation for building multiplayer games in Unity? I know, I know, I should learn to code first before jumping into multiplayer games, but I went through this tutorial and it all seemed fairly straight-forward to me. However, there's a few things I don't understand how to do, like make player-classes or build a round-based gametype, so I'd appreciate any materials that focus on that.

  35. Post #2675
    KillaMaaki's Avatar
    August 2013
    1,100 Posts
    New video of what I'm now calling "SkyRay".


    - I was previously porting over atmospheric scattering code from Unity's builtin skybox. I've now got a completely new method which precalculates sun angles and ray angles into a set of 3D LUTs (64x64x64) and just samples from that texture at runtime. The new scattering is based on Eric Bruneton's precomputed atmospheric scattering method, known for being one of the better-looking methods. It tends to produce much better sunset and twilight colors (for example, it even reproduces earth's shadow on the atmosphere at sunset). An editor utility is provided which allows people to compute their own, based on custom planet radius, atmosphere radius, atmosphere density, scattering wavelengths, atmosphere color, etc.

    - For a while I had automatic sun colors based on rayleigh scattering. Now I've gone back to a custom gradient, but you can now auto-generate a gradient from rayleigh scattering, and then go in and manually tweak. For example, in the above video I've tweaked the sunset colors for a slightly more saturated orange.

    - Showing off the weather system with a storm cloud rolling in and raining over the player. Particles and sounds can be easily tied into various values driven by the weather engine (cloud cover, moisture, temperature, etc).tc).

    Also, the cloud rendering has been verified 100% compatible with WebGL 2.0 (requires ES3.0 or higher, so it doesn't work in WebGL 1.0)

    EDIT so I don't just make a double post.

    MOON PHASES! And also better moon position calculation.


    Just ended up doing a dot product of sunlight direction with spherical normal map. Turns out it's relatively accurate to real-world moon phases (checked with online lunar calendars), and I didn't even have to try and find an algorithm for moon phase calculation. It just works.

    Also using a whole new CelestialBody system. My sun and moon now go through the exact same code, but with different parameters which define their orbits (as well as the starfield, which now rotates independently of the sun). Which also means custom planets with custom orbits can be passed into the same calculations. Which is awesome.
    Reply With Quote Edit / Delete Reply Windows 10 Chrome United States Show Events Winner Winner x 3 (list)

  36. Post #2676
    pierre0158's Avatar
    June 2010
    188 Posts
    -snip, nvm-

  37. Post #2677
    Gold Member
    Richy19's Avatar
    May 2010
    5,735 Posts
    Do many/any of you compile your scripts exclusivelly to DLL's? And then use these in Unity
    Reply With Quote Edit / Delete Reply Windows 10 Chrome United Kingdom Show Events Disagree Disagree x 1 (list)

  38. Post #2678
    Fourier's Avatar
    July 2014
    3,927 Posts
    No Richy19, why?

  39. Post #2679
    Gold Member
    Richy19's Avatar
    May 2010
    5,735 Posts
    No Richy19, why?
    I just wondered what the workflow was for most, I find using DLL's make it neater and let you use newer features (this may be mute in newer versions of unity) but come with some downsides (mostly the click-logger kinda breaks)

  40. Post #2680
    Fourier's Avatar
    July 2014
    3,927 Posts
    Hello, what is best way to do code multiplayer in Unity? I want multiplayer to be like in CS:GO. I want to do MP, where:
    - server is authoritative,
    - players only send commands where they want to go (WASD), server simulates and corrects players
    - client-side prediction
    - lag compensation, server simulates for each player

    Any suggestions? Would appreciate any links to assets/libraries/tutorials.

    I just wondered what the workflow was for most, I find using DLL's make it neater and let you use newer features (this may be mute in newer versions of unity) but come with some downsides (mostly the click-logger kinda breaks)
    Ahh ok :). Yes, it might be neater also in performance sense, since you don't need to recompile everything every time. But that is good only for stable code.
    Reply With Quote Edit / Delete Reply Windows 10 Chrome Slovenia Show Events Agree Agree x 1 (list)