Hi, is there a way to make an object fade to nothing before destroying it? It would look better, rather than having it just disappear.
Could you not change the alpha section of the object material(s) over time? You would need to change your shaders to transparent versions so Iâm not sure how they would look etc. Worth doing a test or two me thinks.
You could then have a quick check, if alpha <= 0 destroy the object.
Regards,
Matt.
You could use this framework for that exact thing: http://forum.unity3d.com/viewtopic.php?t=47351&postdays=0&postorder=asc&start=0
I think I will use alphas, but how would I do that? I dont change textures much, so IDK how I would do itâŚ
Any one? But what is an alpha anyway? Would i use:renderer.material.a = 0
Or something like that? And doesnt changing the alpha on 1 material cause all the objects in the scene to become transparent too?
Make sure the materialâs shader allows transparency (say, the Transparent/Diffuse shader). Every material has a color parameter; change the alpha value of it to 0 for full transparency.
renderer.material.color.a = 0;
For the fade effect, I recommend using the Animation editor to animate the alpha parameter; no additional framework required. Simply trigger this animation and wait for its completion before destroying the object.
No. The material attached to a game object is an instance of that material. Just like you can change the parameters of a script and other objects with that same script attached remain unaffected.
iTween can do th e fade effect with one line of code i belive. i plan to use it for the same effect.
You are correct, then add an onComplete callback that destroys the object.
Hereâs how with iTween:
function Start () {
iTween.fadeTo(gameObject,{"alpha":0, "onComplete":"destroy"});
}
function destroy():void{
Destroy(gameObject);
}
But how would I make the alpha so I can animate it anyway?
Every Color has an alpha value already, no need to âmakeâ it. As I mentioned above, set your materialâs shader to Transparent/Diffuse (or some variation) and animate the alpha value of the materialâs colour however you please.
Update v1.0.14:
- Changed punchPosition and shake to use localPosition instead of worldPosition
- Fixed shakeâs callback routine
- Added âloopTypeâ argument for most methods (check the documentation for which ones now have it) with the ability to set it as âloopâ or âpingPongâ (thereâs issues with the moveToBezier and moveToBezierWorld that I âmayâ get to)
- Added new sample project to support page
UPDATE:
*JavaScript version of iTween is now 1.0.15
*I threw together a simple game with source code for everyone on the support site to help show some uses of iTween in an actual project.
*New video on the support site that goes through EVERYTHING that iTween can currently do for you!
What about using Mathf.Lerp(1,0,10);? Well, anyway, how would I change the alpha on all the childrenâs textures as well?
I guess youâd have to add them one by one to an iTween.fade. Yeah?
Update: v 1.0.17
For those who prefer using native data types instead of separating out individual properties (âxâ,âyâ, etcâŚ) Iâve added a ton of new properties that leverage Vector3 and such - check the documentation for details.
Added âpositionâ:Vector3 to moveTo, moveToWorld, moveFrom, moveFromWorld
Added âamountâ:Vector3 to moveBy, moveByWorld
Added âcolorâ:Color to colorTo, colorFrom
Added âscaleâ:Vector3 to scaleTo, scaleFrom
Added âamountâ:Vector3 to scaleBy, scaleAdd
Added ârotationâ:Vector3 to rotateTo, rotateFrom
Added âamountâ:Vector3 to rotateBy
Added âpositionâ:Vector3 to punchPosition
Added ârotationâ:Vector3 to punchRotation
Added âamountâ:Vector3 to shake
Examples:
iTween.colorFrom(gameObject,{"color":Color.yellow});
iTween.colorTo(gameObject,{"r":2,"delay":3});
iTween.moveFrom(gameObject,{"position":Vector3(-1,-1,-1)});
iTween.moveFromWorld(gameObject,{"position":Vector3(-1,-1,-1)});
iTween.moveTo(gameObject,{"x":2,"delay":2});
iTween.moveTo(gameObject,{"position":Vector3(0,0,0),"delay":4});
iTween.scaleTo(gameObject,{"scale":Vector3(2,2,2)});
iTween.scaleFrom(gameObject,{"scale":Vector3(2,2,2)});
iTween.moveByWorld(gameObject,{"amount":Vector3(2,2,2)});
iTween.rotateTo(gameObject,{"rotation":Vector3(12,12,12)});
iTween.rotateFrom(gameObject,{"rotation":Vector3(12,12,12)});
iTween.scaleAdd(gameObject,{"amount":Vector3(2,2,2)});
iTween.scaleBy(gameObject,{"amount":Vector3(2,2,2)});
iTween.rotateBy(gameObject,{"amount":Vector3(.5,0,0)});
iTween.punchPosition(gameObject,{"position":Vector3(1,0,0)});
iTween.punchRotation(gameObject,{"rotation":Vector3(.1,0,0)});
iTween.shake(gameObject,{"amount":Vector3(.2,0,0)});
edplane:
Iâll add an option to fadeTo and fadeFrom called âincludeChildrenâ:Boolean that will be true by default and it will automatically fade all children. Cool??
edplane:
Version 1.0.18 is now live and the color and fade methods automatically effect any children objects (you can toggle this behavior with âincludeChildrenâ).
Cool?
UPDATE JS v 1.0.20
- Smoothed out orientToPath controls for bezier movements
- Fixed some slight issues with local and world space with bezier movements
- moveToBezier (only using local) with orientToPath doesnât work for correct lookAt on contained objects (objects that have a parent) - ANY SUGGESTIONS?
- Deleted moveByWorld since it wasnât logical (if this is in error, let me know)
- moveFrom wasnât calculating correctly between local and world space - does now
- Fixed pingPong loop failures throughout
- Added rotateAdd
- Rotational math for local usage is still odd - ANY SUGGESTIONS?
- Fixed pingPong loops on bezier movements
- Added loopType to scaleBy, scaleAdd, rotateBy, rotateAdd
UPDATE: JavaScript v 1.0.23
This version ushers in the first of many new âContinuously Callableâ methods. Thatâs right boye and girls, no more hunting around for smooth camera controllers and the like! You can easily cause iTween to act as a smooth camera follow script by the first offering called lookToUpdate:
var target : Transform;
function Update () {
iTween.lookToUpdate(gameObject,{"target":target.position, "lookSpeed": 3}a;
}
Just released a sizable update to the JavaScript version, can you guys let me know if any new bugs crept up!
1.0.28 JavaScript iTween
Fixed:
-All âByâ and âAddâ move methods can now take âpositionâ or âamountâ
-All âByâ and âAddâ rotate methods can now take âpositionâ or âamountâ
-Every âByâ and âAddâ method now snapshots itâs start position when it is run rather than when its initialized to avoid odd behaviours when delays ae utilized
-Changed lookFrom to use startRotation not endRotation
-Added moveAdd to enhance flexibility
-Cleaned up and optimized all move methods to be more predictable and reliable (utilizing Translate for better local space movement)
-Cleaned up and optimized all rotate methods to be more predictable and reliable (utilizing Rotete for better local space movement)
-Cleaned up and optimized punchPosition and punchRotation to be more predictable and reliable (utilizing Translate for better local space movement)
-Cleaned up and optimized all scale methods to be more predictable and reliable
-Added lookToUpdateWorld and corrected world usage for lookToUpdate
-Corrected issue with bezier move and orientToPath failing if the object was a child
-Bezier move now uses lookToUpdateWorld regardless of situation (I âthinkâ this is the correct solution)
-Added moveToUpdateWorld
-Added axis argument to bezier move to allow locking of look application to single axis
-Bezier move lookAt now uses lookToUpdateWorld
-Added lookToWorld
-MoveBy and MoveAdd are now identical in operation
-Added shakeWorld
-Shake methods not correctly resolve magnitude to 0
-Consolidated rotateToDefaults and rotateByDefaults into rotateDefaul