Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Pulluxx

Pages: [1]
1
Support / Rotating sprites
« on: May 30, 2013, 12:20:54 pm »
Hey! I'm working on putting in movement patterns in our game, and we want the animated sprites to look at the position it's going to while moving. This is my code so far (where m_NextNode.m_Position is the Vector3 the animated sprite is heading towards):

Code: [Select]
Quaternion rotation = Quaternion.LookRotation((m_NextNode.m_Position - transform.position).normalized, transform.up);
Vector3 tempRot = rotation.eulerAngles;
tempRot.y -= 90f;
tempRot.z *= -1f;
transform.rotation = Quaternion.Euler(tempRot);

This works pretty OK at certain angles, though at some angles the sprite turns upside down or gets another strange rotation (this happens mostly between vectors with big differences on the y-axis). I'm wondering if you could help me out with the rotation. Is there any rotation function in 2D Toolkit you should use? Do I need to flip the animations in some way (however I haven't had any problem with animated sprites changing 'direction' on the x-axis so far)?

2
Support / Getting AnimatedSprite's textures
« on: May 20, 2013, 04:39:48 pm »
Hey!  :)

I want to be able to modify the hue and saturation of an animated sprite during runtime. I've looked around a bit, and found a HSV color-struct which will help me out with this. This code works for a Texture2D:

Code: [Select]
void SetSaturation(float saturation)
{

  texture2D = animSpriteTexture;

Color[] pixels = texture2D.GetPixels();

for (int i = 0; i < pixels.Length; i++)
{

HSVColor temp = HSVColor.FromColor(pixels[i]);
temp.s = saturation;
pixels[i] = temp.ToColor();
}

texture2D.SetPixels(pixels);
texture2D.Apply ();
}

So what I'd like to do is to either:

1. Have a script (which probably inherits from tk2dAnimatedSprite) that for every frame can get the current frame's Texture2D at runtime and then run this function.

2. Perhaps get the GameObject's atlas and apply the changes to the whole atlas.

How would I go about this? I want to be able to only modify one GameObjects saturation this way (and let all other GameObjects which have the same AnimLib have their own saturation), so I'm wondering, GameObjects which share the same AnimLib, do they have an unique atlas for their animations or do they all share one?

3
Support / Custom Shaders
« on: May 15, 2013, 01:08:30 am »
Hey there  :)

In our game we have a custom shader we want to use on our animated sprites. What we want to have is a detail texture which are multiplied with the animated sprites texture to simulate that the creature that is the animated sprite is sick. What happens when we use it, is that the detail texture changes position for every frame and the dots which we have as detail appear in a lot of different places. We think this problem could be solved if we could get a new UV2 map for each frame in the animation and then use it in the shader. Is there a way to get this?

This is how the shader looks:

Code: [Select]
Shader "Custom/DiffuseDetailCuttoff"
{
Properties
{
_DiseaseColor ("Disease Color", Color) = (1,1,1,1)
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_DetailTex ("Detail Texture", 2D) = "white" {}
_DetailFade ("Defail Fade", Range(0, 1)) = 1.0
_DetailTiling ("Detail Tiling", Float) = 1.0


}

SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off Lighting Off Cull Off Fog { Mode Off } Blend SrcAlpha OneMinusSrcAlpha
LOD 110

Pass
{
CGPROGRAM
#pragma vertex vert_vct
#pragma fragment frag_mult
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"

sampler2D _MainTex;
half4 _MainTex_ST;
sampler2D _DetailTex;
fixed4 _DiseaseColor;
fixed4 _Color;
half _DetailTiling;
fixed _DetailFade;

struct vin_vct
{
half4 vertex : POSITION;
half4 color : COLOR;
fixed2 texcoord : TEXCOORD0;
};

struct v2f_vct
{
half4 vertex : POSITION;
fixed4 color : COLOR;
fixed2 texcoord : TEXCOORD0;

};

v2f_vct vert_vct(vin_vct v)
{
v2f_vct o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = v.texcoord;
return o;
}

fixed4 frag_mult(v2f_vct i) : COLOR
{
fixed4 col = tex2D(_MainTex, i.texcoord) * i.color;
fixed4 det = tex2D(_DetailTex, i.texcoord * _DetailTiling);

fixed3 minusDet = 1 - det;
col *= _Color;
col.rgb += lerp(det.rgb * _DiseaseColor.rgb, (0,0,0), _DetailFade);
return col;
}
ENDCG
}
}
 
SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off Fog { Mode Off }
LOD 100

BindChannels
{
Bind "Vertex", vertex
Bind "TexCoord", texcoord
Bind "Color", color
}

Pass
{
Lighting Off
SetTexture [_MainTex] { combine texture * primary }
}
}
}

4
Support / All of my animated sprites disappeared
« on: May 04, 2013, 11:52:27 am »
Hey guys.

I tried to give an animated sprite one of Unity's particle shaders, and selected a texture for it. When I then wanted to revert everything to normal, and give the animated sprite a unlit/transparent shader the animation disappeared and all animated sprites are rectangles instead. I would appreciate some help on how to get everything back to normal. Does shader selection for animated sprites affect all of them, and if so, how can I go back to just unlit/transparent with no texture?

Pages: [1]