• Unity3D - Discussion
    5,004 replies, posted
Oooooh yes someone else brings up something I absolutely ADORE in C#... Anonymous functions! We're using these heavily in DFTween (a tween library we're working on) Check this out: [code] var aMethod = () => { /* code here */ } // later aMethod(); [/code] Funky looking syntax, but really it's easy to understand: [code] () // these are the parameters => { // this is the function body } [/code] So you could so stuff like this: [code] System.Action<int,int> addNumbers = ( a, b ) => { return a+b; } int sum = addNumbers( 10, 5 ); Debug.Log( sum ); // prints '15' [/code] Which is used quite heavily in LINQ, by the way: [code] var enemy = Enemies.Where( x => { return IsInRange( x ); } ) .OrderBy( x => { return DistanceTo( x ); } ) .FirstOrDefault(); [/code]
What do you guys think the best way of handling decals/blood decals in Unity? As an example, I'm actually not sure how I'd do this. So I'm asking. Anyways, in my top-down shooter. I want blood decals to spray across the floor, when a rigidbody hits an enemy. I've heard of using raycasts for bullet holes. But I'm using an actually physics object for my bullet, so I'm not sure how I'd instantiate a decal on the floor, when an enemy is shot. I had another idea, of instantiating blood gibs, when the enemy is hit, and then instantiate the blood decal when the gib hits the floor, that's more what I'm aiming for, but again. Not sure how I'd get the decal on the floor properly, and detect when the gib hit it.
[QUOTE=sarge997;44825807]What do you guys think the best way of handling decals/blood decals in Unity? As an example, I'm actually not sure how I'd do this. So I'm asking. Anyways, in my top-down shooter. I want blood decals to spray across the floor, when a rigidbody hits an enemy. I've heard of using raycasts for bullet holes. But I'm using an actually physics object for my bullet, so I'm not sure how I'd instantiate a decal on the floor, when an enemy is shot. I had another idea, of instantiating blood gibs, when the enemy is hit, and then instantiate the blood decal when the gib hits the floor, that's more what I'm aiming for, but again. Not sure how I'd get the decal on the floor properly, and detect when the gib hit it.[/QUOTE] I'm starting to look into this now. It's hard to believe that Unity don't have this support built in. The addons on the store do it by tracing and grabbing all the triangles, then making a new mesh and a new renderer. This seems like it'd work great.. but I'm not sure how well it would work for skinned meshes.
[QUOTE=sarge997;44825807]What do you guys think the best way of handling decals/blood decals in Unity? As an example, I'm actually not sure how I'd do this. So I'm asking. Anyways, in my top-down shooter. I want blood decals to spray across the floor, when a rigidbody hits an enemy. I've heard of using raycasts for bullet holes. But I'm using an actually physics object for my bullet, so I'm not sure how I'd instantiate a decal on the floor, when an enemy is shot. I had another idea, of instantiating blood gibs, when the enemy is hit, and then instantiate the blood decal when the gib hits the floor, that's more what I'm aiming for, but again. Not sure how I'd get the decal on the floor properly, and detect when the gib hit it.[/QUOTE] Unity has projectors that project a texture on already existing models. [url]http://docs.unity3d.com/Documentation/Components/class-Projector.html[/url] The only problem is, is that the shaders that come with the standard assets don't check from which direction you're projecting, so it does it on both sides of the objects it's projecting on.
That'd work.. I wonder how fast it is.. only one way to tell I guess.
I'm messing around with networking, and it's working fine, I'm able to create two players, but I can't seem to get cameras to work on each player. The player is a prefab, which I create by making a public GameObject, then assigning it through unity's Inspector, and the prefab has a camera child (Parent or what you call it.) but it doesn't move with the player.
[QUOTE=Persious;44826445]I'm messing around with networking, and it's working fine, I'm able to create two players, but I can't seem to get cameras to work on each player. The player is a prefab, which I create by making a public GameObject, then assigning it through unity's Inspector, and the prefab has a camera child (Parent or what you call it.) but it doesn't move with the player.[/QUOTE] If you're not directly touching the camera's position, then of course it is. You're probably just seeing the wrong camera view (forgetting to disable cameras of remote players?)
[QUOTE=sarge997;44825807]What do you guys think the best way of handling decals/blood decals in Unity? As an example, I'm actually not sure how I'd do this. So I'm asking. Anyways, in my top-down shooter. I want blood decals to spray across the floor, when a rigidbody hits an enemy. I've heard of using raycasts for bullet holes. But I'm using an actually physics object for my bullet, so I'm not sure how I'd instantiate a decal on the floor, when an enemy is shot. I had another idea, of instantiating blood gibs, when the enemy is hit, and then instantiate the blood decal when the gib hits the floor, that's more what I'm aiming for, but again. Not sure how I'd get the decal on the floor properly, and detect when the gib hit it.[/QUOTE] Gibs making decals on the floor is probably the way you want to go. For the gibs you could just model them with physics (rigidbody) and make a quick script that uses OnTriggerEnter to spawn a decal and destroy itself (the gib). I would think the easiest way to do decals would be to just make them 2-poly squares with a texture that utilizes transparency and place them on the point of collision, facing up.
Can someone help me understand how to apply force to a Rigidbody, opposite of the angle it hit a object at?
[QUOTE=Garrison;44829103]Can someone help me understand how to apply force to a Rigidbody, opposite of the angle it hit a object at?[/QUOTE] [url=https://docs.unity3d.com/Documentation/ScriptReference/Vector3.Reflect.html]Vector3.Reflect[/url] Or do you want to reverse the direction of motion?
Okay this is a super dumb question, but are all the values PlayerPrefs loaded in the ram at all times? If so, my current project is fucked because I'm a crappy programmer.
[QUOTE=KillaMaaki;44823927] 2.) Interesting, hadn't heard of this before. I've always discarded the first iteration to account for JIT compilation. [/QUOTE] One example would be that the jitter can (and will) recompile some callsites that make use of dynamic dispatching. When a method call ends up being dispatched to the same implementation more than 100 consecutive times a shortcut [I]can[/I] be compiled into the callsite that gives a small but noticable performance boost.
[QUOTE=Pelf;44829126][url=https://docs.unity3d.com/Documentation/ScriptReference/Vector3.Reflect.html]Vector3.Reflect[/url] Or do you want to reverse the direction of motion?[/QUOTE] I want to make those pinball pegs that when the ball hits it, it goes flying right back in the direction it came.
[QUOTE=Garrison;44830138]I want to make those pinball pegs that when the ball hits it, it goes flying right back in the direction it came.[/QUOTE] I don't know whether you want to reflect it properly, or actually have it always go straight back in the direction it's coming from. But here's the way you'd do it if you don't want proper reflection. [CODE]rigidbody.addForce( ( -rigidbody.velocity/Time.fixedDeltaTime ) * 2 )[/CODE] This should do the trick. [editline]17th May 2014[/editline] Let me explain why this works too. Unity doesn't give you access to the acceleration of an object. But since velocity is just acceleration multiplied by time, if we divide by time we get back the acceleration of [I]this[/I] frame. I'm using fixedDeltaTime so that there is no fluctuation in the timestep, and so the answer is accurate. Lastly, you multiply by two to reverse the direction.
How do you turn off the ugly directional light shadows in the free version?
[QUOTE=amgoz1;44832955]How do you turn off the ugly directional light shadows in the free version?[/QUOTE] Read the documentation. There's a dropdown right in the directional light inspector for turning off shadows.
[QUOTE=amgoz1;44832955]How do you turn off the ugly directional light shadows in the free version?[/QUOTE] If they're too pixelated, turn down the range of the dynamic shadows, improves the quality tons. Anyway, anybody now how to "subtract" a circle from another? I have a linerender that draws a circle of an objects range, and I want it to curve around objects. Right now I'm achieving this by doing a raycast from the object to every point where the linerender should be, but this lags the absolute shit out of everything(obviously). Anyone have a better approach than mine?
[QUOTE=garry;44826041]I'm starting to look into this now. It's hard to believe that Unity don't have this support built in. The addons on the store do it by tracing and grabbing all the triangles, then making a new mesh and a new renderer. This seems like it'd work great.. but I'm not sure how well it would work for skinned meshes.[/QUOTE] [URL]http://forum.unity3d.com/threads/184596-Texture-Packer-Unity-Tutorial[/URL] ? Oh decals.. nevermind
[QUOTE=KillaMaaki;44832984]Read the documentation. There's a dropdown right in the directional light inspector for turning off shadows.[/QUOTE] That doesn't disable it and neither does turning off shadow casting on objects.
[QUOTE=amgoz1;44835132]That doesn't disable it and neither does turning off shadow casting on objects.[/QUOTE] What ugly shadows are you referring to then? Screenshots?
How can I efficiently get all entries of a dictionary whose keys are within a specified range? In my case the key would be a float, and I want to return all entries where that float is within the range f.ex 0 - 50.47f. Should I not be using a dictionary at all for this?
[QUOTE=KillaMaaki;44835276]What ugly shadows are you referring to then? Screenshots?[/QUOTE] After updating to 4.3.4 my directional light is casting realtime shadows. [thumb]http://i.imgur.com/hzv1M9H.jpg[/thumb]
How would you guys go about checking if a character is on the ground or not, getting the surface normal if it is and like source if the ground is only a certain distance high moving it onto it and vice versa.
[QUOTE=amgoz1;44835528]After updating to 4.3.4 my directional light is casting realtime shadows. [thumb]http://i.imgur.com/hzv1M9H.jpg[/thumb][/QUOTE] How many lights are in your scene?
[QUOTE=amgoz1;44835528]After updating to 4.3.4 my directional light is casting realtime shadows. [thumb]http://i.imgur.com/hzv1M9H.jpg[/thumb][/QUOTE] Can you post a screenshot of your directional light in the inspector?
[QUOTE=Pelf;44839931]Can you post a screenshot of your directional light in the inspector?[/QUOTE] [IMG]http://imgur.com/FvrUkN3.jpg[/IMG]
[IMG]http://puu.sh/8OxyU.png[/IMG] What is Gfx.WaitForPresent and why is it being a bitch on my kindle fire HD 7? Vsync is off, it's a 2d game
[QUOTE=amgoz1;44840234][IMG]http://imgur.com/FvrUkN3.jpg[/IMG][/QUOTE] Try disabling every light in the scene until the shadow goes away?
[QUOTE=amgoz1;44840234][IMG]http://imgur.com/FvrUkN3.jpg[/IMG][/QUOTE] The bolded fields mean they differ from the source prefab right? Maybe try "apply" to save settings at the top of the inspector window or finding the culprit light and hitting revert to prefab to make it adopt the original prefab's settings?
[QUOTE=Pelf;44840277]Try disabling every light in the scene until the shadow goes away?[/QUOTE] Deleting or disabling the directional light is the only thing that affects the shadow. If I create a blank scene with a default directional light and a box the problem persists.
Sorry, you need to Log In to post a reply to this thread.