Unity Motion blur Skills

Source: Internet
Author: User

Artifact implementation:

1, list<drawmesh> list, this list contains a frame animation model grid, material

2. Add the model of the moving object to the list each time (optimization: not implemented, mesh merging)

3, lateupdate all the model material Alpha in the list is reduced to 0, then remove; the rest of the model DrawMesh

Skill implementation:

The skill is two parts, the former part is the motion remnant shadow, the latter part is the ground explosion, the association process can be processed.

Ps

This simple implementation of this skill, but should be able to do better, is to add state to the moving object: Air, will be landing, need to maintain these two states, and need to use ray processing to put the explosive particles in the appropriate location play

Code:

1 usingUnityengine;2 usingSystem.Collections;3 usingSystem.Collections.Generic;4 5 classDrawMesh6 {7      Publicmesh mesh;8      Publicmatrix4x4 Matrix;9      PublicMaterial Material;Ten      PublicDrawMesh (Mesh me, matrix4x4 ma, Material mat, color color) One     { A          This. Mesh =me; -          This. Matrix =Ma; -          This. Material =NewMaterial (MAT); the          This. Material.shader = Shader.find ("Transparent/vertexlit"); -          This. Material. SetColor ("_emission", color); -     } - } +  -  Public classSkill4:monobehaviour + { A     Privateskinnedmeshrenderer[] render; at      -      -      Public floatForwardpower;//Moving Speed -      Public floatJumppower;//Jumping Speed -     Private BOOLIsstart;//whether the shadow starts -  in      Public floatSkill4continuetime;//total duration of the residual shadow process -     Private floatTime ; to      Public floatFadespeed;//shadow fade fade rate +  -      Public floatRate//Draw the shadow rate the      PublicColor color;//Shadow color *     PrivateList<drawmesh> list;//Ghost List $ Panax Notoginseng      PublicParticlesystem particle;//End Explosive particles -     PrivateVector3 particleposition;//particle initial position, particle hanging on player the  +  A     voidAwake () the     { +Render = Getcomponentsinchildren<skinnedmeshrenderer>(); -List =NewList<drawmesh>(); $Isstart =false; $Time =0; -Particleposition =particle.transform.localPosition; -     } the  -     voidUpdate ()Wuyi     { the         if(Input.getkeydown (KeyCode.H)) -         { Wu Useskill (); -         } About     } $  -      Public voidUseskill () -     { -Playercs.crossfade ("Attack3anim", 0f); AIsstart =true; +Time =0; the Startcoroutine (Iestartskill ()); -     } $  the     PrivateIEnumerator Iestartskill () the     { therigidbody.velocity = rigidbody.velocity + vector3.up * jumppower;//Jumping Speed the          while(Isstart) -         { in              for(inti =0; I < render. Length; i++) the             { theMesh mesh =NewMesh (); About Render[i]. Bakemesh (mesh); theList. ADD (NewDrawMesh (Mesh, Render[i].transform.localtoworldmatrix, render[i].material, color)); the             } the             yield return Newwaitforseconds (rate); +         } -     } the Bayi     voidfixedupdate () the     { the         if(Isstart) -         { -             if(Time < Skill4continuetime)//in the shadow process the             { theTime + =Time.deltatime; theRigidbody.velocity = transform. Transformdirection (Vector3.forward * forwardpower) + vector3.up *rigidbody.velocity.y; the             } -             Else//The shadow process ends into the explosion process the             { theIsstart =false; theRigidbody.velocity = vector3.up*rigidbody.velocity.y;94Playercs.crossfade ("Idleanim", 1f); the Startcoroutine (Ieboom ()); the             } the         }98     } About  - IEnumerator ieboom ()101     {102Particle.transform.parent =NULL;103 104Particle.gameObject.SetActive (true); the particle. Play ();106         yield return NewWaitforseconds (particle.duration);//The explosion process is over .107Particle.gameObject.SetActive (false);108Particle.transform.parent =transform;109Particle.transform.localPosition =particleposition; the     }111  the     voidlateupdate ()113     { the          for(inti = list. Count-1; I >=0; i--) the         { theList[i].material. SetColor ("_color",NewColor (COLOR.R, COLOR.G, color.b, List[i].material.color.a-time.deltatime *fadespeed));117             if(List[i].material.color.a <=0.05f)118             {119Destroy (list[i].material);//important, if not destroy memory occupies more and more - Destroy (List[i].mesh);121 list. RemoveAt (i);122             }123         }124          for(inti = list. Count-1; I >=0; i--) the         {126 Graphics.drawmesh (List[i].mesh, List[i].matrix, list[i].material, gameobject.layer);127         } -     }129}
View Code

Effect:

Unity Motion ghosting Skills

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.