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.


Messages - TekuStudios

Pages: 1 ... 4 5 [6] 7
76
Support / Our per-object Motion Blur solution: use it if you want!
« on: June 18, 2013, 10:30:07 am »
So, we've been working on an object-independent motion blur for sprites. We've reached a somehow useful solution, so we are posting it here for you guys, in case that someone needs something similar. It only works with the next 2DToolkit 2.2.

First, the Motion Blur script (component of the object to be blurred):
Code: [Select]
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MotionBlurHandler : MonoBehaviour
{
        //Will it be a blur over the object, or a trail behind it?
        public bool front = true;
        //How much speed does the object need before blurring?
public float startSpeed = 0.005f;
        //How much time does it take for each 'copy' to fade?
public float copyFadeTime = 0.1f;
//The sprite object that will be duplicated (could be changed to 'tk2dSprite')
public GameObject trailMotionSpriteObject;
        //The script handles this
public Material fadeMaterial;
        //How many copies does the trail create?
public float maxCopies = 5.0f;
        //How many offset between copies?
public float offsetCopies = 0.01f;
        //How much time does it take to each copy to spawn?
public float timeBetweenCopies = 0.02f;
        //The alpha of the first copy
public float initAlpha = 0.5f;
        //The amount of alpha substracted between copies
public float alphaOffset = 0.15f;

private tk2dSprite _mySprite;
private float _timer;
private bool _createNow;
private int _currentCopies;
private int _currentLayer;
private Vector3 _currentOffset;
private float _currentAlpha = 1.0f;
private List<GameObject> _copyList;

void Start()
{
_copyList = new List<GameObject>();
_currentOffset = Vector3.zero;
_currentAlpha = initAlpha;
_mySprite = GetComponent<tk2dSprite>() as tk2dSprite;
}

void Update()
{
if(_timer <= timeBetweenCopies)
{
_createNow = false;
_timer += Time.deltaTime;
}
else
{
_createNow = true;
_timer = 0.0f;
}

if(Mathf.Abs (Vector3.Magnitude(rigidbody.velocity)) > startSpeed )
{
if(_currentCopies < maxCopies)
{
if(_createNow)
{
Vector3 tmpVelocity = rigidbody.velocity;
tmpVelocity.y = 0.0f;
_currentOffset += (Vector3.Normalize(tmpVelocity) * offsetCopies);
_currentAlpha -=  alphaOffset;
Vector3 tmp = Vector3.zero;
tmp.x = transform.localPosition.x-_currentOffset.x;
tmp.y = transform.localPosition.y-_currentOffset.y;
tmp.z = transform.localPosition.z-_currentOffset.z;

GameObject go = Instantiate(trailMotionSpriteObject,transform.localPosition-_currentOffset, transform.rotation) as GameObject;

_copyList.Add(go);
++_currentCopies;
if(front)
++_currentLayer;
else
--_currentLayer;

FadeInTime fit = go.AddComponent("FadeInTime") as FadeInTime;
(go.GetComponent<tk2dSprite>() as tk2dSprite).RenderLayer = _currentLayer;

go.renderer.material = renderer.material;
fit.SetInitAlpha(_currentAlpha, this);
go.transform.parent = gameObject.transform;
}
}
}
else
{
if(_currentCopies != 0)
{
(_copyList[_currentCopies-1].GetComponent<FadeInTime>() as FadeInTime).StartFading(copyFadeTime);
_copyList.RemoveAt(_currentCopies-1);
--_currentCopies;

if(_currentCopies == 0)
{
_currentOffset = Vector3.zero;
_currentAlpha = initAlpha;
_currentLayer = 0;
}
}
}
}

And the other one. This is a script that the previous one adds at runtime to each copy:
Code: [Select]
using UnityEngine;
using System.Collections;

public class FadeInTime : MonoBehaviour
{
public float fadeTime = 0.5f;
public Transform followPosition;
private bool _ready = false;

public tk2dSprite mySprite;
private float _timePassed = 0.0f;
private float _initAlpha;
private MotionBlurHandler _motionHandler;

void Start ()
{
//mySprite = gameObject.GetComponent<tk2dAnimatedSprite>() as tk2dAnimatedSprite;
mySprite = gameObject.GetComponent<tk2dSprite>() as tk2dSprite;
}

void Update ()
{
if(_ready)
{
_timePassed += Time.deltaTime;

if(_timePassed < fadeTime)
{
Color myColor = new Color();
myColor.r = mySprite.color.r;
myColor.g = mySprite.color.g;
myColor.b = mySprite.color.b;
myColor.a = Mathf.Lerp (_initAlpha,0.0f,_timePassed/fadeTime);
mySprite.color = myColor;

//Movement
// delayed follower
/*float distance = Vector3.Distance(transform.position, followPosition.position);

if(distance>0)
{
Vector3 nextPosition = Vector3.Lerp (transform.position, followPosition.position, _timePassed/fadeTime);
transform.position = nextPosition;
}*/
}
else
{
Destroy (gameObject);
}
}
}

public void StartFading(float fTime)
{
fadeTime = fTime;
_ready = true;
}

public void SetInitAlpha(float initAlpha,MotionBlurHandler mh )
{
_initAlpha = initAlpha;
_motionHandler = mh;
//mySprite = gameObject.GetComponent<tk2dAnimatedSprite>() as tk2dAnimatedSprite;
mySprite = gameObject.GetComponent<tk2dSprite>() as tk2dSprite;
Color myColor = new Color();
myColor.r = mySprite.color.r;
myColor.g = mySprite.color.g;
myColor.b = mySprite.color.b;
myColor.a = _initAlpha;
mySprite.color = myColor;

//MeshRenderer m = gameObject. GetComponent<MeshRenderer>() as MeshRenderer;
//renderer.sharedMaterial = mat;
}
}

What this system does is fairly simple: the first script instantiates copies of the original sprite with a very tiny offset, and gives them a certain amount of alpha. This creates an illusion of blurriness over the gameobject, and it only works when it is moving. The second script just handles some fading effect for the copies.

Hope you guys find it useful! :)

77
Support / Re: Assigning new material to a duplicated sprite
« on: June 17, 2013, 06:11:49 pm »
Ok, we've spent the whole day but we managed to successfully upgrade our current project to 2.0+hotfix 1. It works perfect and the layering system you sent us has been doing well with our faked motion blur script.

78
Releases / Re: 2D Toolkit 2.0 final + hotfix 1
« on: June 17, 2013, 06:10:32 pm »
Ok, we've spent the whole day but we managed to successfully upgrade our current project to 2.0+hotfix 1. It works perfect and the layering system you sent us has been doing well with our faked motion blur script.

79
Support / Re: Assigning new material to a duplicated sprite
« on: June 11, 2013, 06:01:16 pm »
Email sent :)

80
Support / Assigning new material to a duplicated sprite
« on: June 11, 2013, 05:46:21 pm »
Hi, here we come with yet another question.

We are coding some custom faked "per-object" motion blur. We don't want a blur effect that affects the whole camera, but one that only applies to specific gameobjects. Since our game is 100% sprite based, we've came up with a peculiar solution.

When a gameobject is moving with certain velocity, we instantiate 4 sprite objects that have the same sprite as the original, give them a tiny X-Axis offset from the original position and -20% alpha each, so this creates an illusion of a "trail" that progressively fades when a object is moving fast.

This works and creates a rather nice visual effect, however all the sprite clones are rendered OVER the original sprite due to perspective issues, and we want them to be rendered behind it. Since our camera is special, we can't just displace them in the Z-Axis to hide them. To control the drawing order of the camera, we assign each "layer" of a scene a unique "Transparent" shader (Transparent+1, Transparent+2...), so the grater ones are drawn later.

So, when instantiating the sprite copies, we assign them a material shader that's 1 layer behind the original sprite material's shader to keep it drawn behind, but it instantly changes into the original's material, so the copies are drawn over the original again due to those perspective issues. Is there a way to prevent this from happening? e.g. copy a sprite, keep the original sprite but change the copy's material shader.


Sorry about the lame explanation, I know it's hard to understand. If you need it I can post a screenshot later. Thanks.

81
Releases / Re: 2D Toolkit 2.0 final
« on: June 01, 2013, 06:11:44 pm »
Unity crushed immediately after double clicking .unitypackage, it shows decompressing package for a second and then crushed.

In fact, that's not the only time it happened, unity seems to like to randomly crush with pakcage import, I have suffer this for quite a bit. Truly annoying for this aspect of unity

You should update every asset via "Assets > Import Package...", otherwise it tends to crash.

82
Releases / Re: 2D Toolkit 2.0 final
« on: June 01, 2013, 11:00:05 am »
Nice! So, the anchoring system goes to 2.1, right? We are waiting for that before updating our current project.

I believe so unless something crops up.

Good to hear that :)

83
Showcase / Re: Tutorials for 2DToolkit available in Spanish
« on: June 01, 2013, 10:33:54 am »
Pues mira, se agradece que alguien se lance a algo así :) es una pena la poca documentación que hay en Castellano con todo lo relacionado con el desarrollo de videojuegos.

Thanks!

84
Releases / Re: 2D Toolkit 2.0 final
« on: June 01, 2013, 10:02:57 am »
Nice! So, the anchoring system goes to 2.1, right? We are waiting for that before updating our current project.

85
Support / Re: Animation event not fired sometimes
« on: May 31, 2013, 01:02:09 pm »
Try some things.

· Do you have some kind of flag in your code? e.g. There's some bool check in your event code that prevents the flow from entering there if certain conditions are met.
· Are you looping the entire animation? e.g. If you are using "Loop section", make sure that the event keyframe is located within the looped section.

So far we haven't experienced any trouble with animation events. In fact, we use them a lot, and the main character alone has more than 50 animations.

86
Support / Re: Unity Versions
« on: May 29, 2013, 10:03:54 am »
Sooner or later everyone is going to upgrade to Unity 4.x, it seems logical that further iterations of 2DToolkit are only designed for it.

87
Releases / Re: 2D Toolkit 2.0 beta 1
« on: May 17, 2013, 10:52:08 pm »
Nice! Any ideas on when will you add the Anchor Points feature? We are kind of desperate for a solution to that.

88
Releases / Re: 2D Toolkit Integrity Checker
« on: May 17, 2013, 01:05:17 pm »
Yay! Huge success!!  8)

89
Releases / Re: 2D Toolkit 1.92 final + patch 1
« on: April 10, 2013, 06:27:28 pm »
Nice! Got it :)

Thank you, and sorry for all the whining  ::)

90
Releases / Re: 2D Toolkit 1.92 final + patch 1
« on: April 10, 2013, 09:37:44 am »
Hey! Did Unity approve your revision? They haven't uploaded it to the Asset Store yet.

Pages: 1 ... 4 5 [6] 7