Is there any chance to get a working navigation system built into unity’s 2D features? Right now you either have to roll your own or forsake most of them in favour of using 3D with 2D elements.
We are also working on bringing the Unity NavMesh to 2D
Any plans to add the ability for an object to awake on a specific distance from the character?
Will there be any fixes for the Trigger2D → Trigger 2D collider issues that have constantly plagued simple hit detection? (Where OnTriggerEnter2D doesn’t fire consistently)
I have a consistently reproducible scenario where 3 identical, unique, unrelated dynamic objects do not even raise the OnTriggerEnter2D event) about 60% of the time against a separate dynamic Trigger2D box collider, despite all 3 interpenetrating the same box using rigidbody2d’s velocity.
You can do this from script pretty easily by comparing the Vector2 distance between the object in question and the player position.
Yes, please!
Thanks @Murgilod . I believe your recommendation is similar/identical to @inthemilkywat , and my answer/follow-up questions can be seen here: http://forum.unity3d.com/threads/how-to-set-object-in-game-to-awaken-on-distance-from-character.327911/#post-2126867
Sorry for the duplication. I guess what I’m asking specifically here in this thread is if there are plans to add the ability for a Rigidbody 2D component to use distance-based settings to awaken an object?
I’ve also added this feature request as a proposal here: https://bitbucket.org/Unity-Technologies/2ddemos/issue/45/set-rigidbody-2d-to-awake-on-distance
Has anyone else had trouble getting the palette to see sprites in the project?
When I load up the example project the palette works like it does int he videos/documentation. When I spin up a blank project and import some sprites, I can’t get the palette to see anything.
Are your individual tile sprites the same size as your TileMap Grid Cell?
My individual tile sprites are 32x32 px (sliced up from a sheet if that matters)
Where should I check the “TileMap Grid Cell”? (I attached a shot of the inspector with my current settings)
Sorry I misunderstood… I’m pretty sure it looks for sprites in sheets that are all the same size… it sounds like a bug.
I can’t wait to get these new additions included in the next version!
This could mean a significant point into 2D game development for sceptic users that still defend frameworks like UbiArt or GameMaker.
So I decided to play around with the masking a bit. I’d like to emphasize the ‘bit’ part since it was only for ten minutes or so, so I’m probably doing something wrong - but the masking seems really weird.
Tried several different sprites as masks and they all churn out unexpected results, such as; not actually masking what they are supposed to mask.
Above gif uses a circle primitive as a mask. Simple Enough.
Also some sort of z-fighting/tearing seems to appear quite frequently on maskable (and outside of??) sprites.
@Greenwar_1 : Masking is based on the stencil, and not alpha. If you go to Shaded-Wireframe mode, you will be able to see the mesh that is generated for the mask, and this mesh is used for masking.
I see, thank you.
Any plans on implementing alpha texture based masking?
@Greenwar_1
We are currently looking at improving stencil based masking and its workflow.
No plans materialised yet for alpha masking.
But if it is a must, I’ve come across some solutions on the asset store that can get you alpha masking right now.
i think i got it (2d sprite alpha mask) working with these shaders
if i remove the ‘discard’ line it looks like the gif above
Shader "Custom/Mask"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
}
SubShader
{
Tags
{
"Queue"="Transparent-1"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ColorMask 0
ZWrite Off
Blend One OneMinusSrcAlpha
Stencil
{
Ref 1
Comp always
Pass replace
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ PIXELSNAP_ON
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
fixed4 _Color;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color;
#ifdef PIXELSNAP_ON
OUT.vertex = UnityPixelSnap (OUT.vertex);
#endif
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
if (c.a < 0.1) discard;
c.rgb *= c.a;
return c;
}
ENDCG
}
}
}
Shader "Custom/Masked"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
Stencil
{
Ref 1
Comp notequal
Pass keep
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ PIXELSNAP_ON
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
fixed4 _Color;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color;
#ifdef PIXELSNAP_ON
OUT.vertex = UnityPixelSnap (OUT.vertex);
#endif
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
c.rgb *= c.a;
return c;
}
ENDCG
}
}
}
Yes… this should work for ON/OFF alpha based on a cut-off threshold.
Although Alpha masks cover gradients also which could prove to be costly.
A shader that multiplies with the texture’s screen space alpha with the mask’s screen space alpha would be more efficient as alpha testing, branching, and discarding pixels are costly for the GPU.
Unfortunately, I’m still in the process of learning shader language, so I’m not prepared to write a proper alpha masking shader yet as I still need to learn the syntax.
In general though, alpha would more useful than stencil for 2D as the stencil requires the manual editing of polygonal shapes for all textures to approximate the shape. Alpha can be set to go with any shape.
Alpha masking is certainly more fancy; but there are pros and cons to each approach.
Stencil based masking is the starting point, but not the end.