Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by maynull · Sep 15, 2014 at 10:42 AM · effectflashtrailcharge

Any idea on this flash/charge effect

Hello there,

I'm trying to make a similar effect like in the visual below. There are 2-3 flash characters appearing and fading out while flash is running. Green arrows on the image is showing what I mean. Is it possible to do similar kind of effect on characters without consuming too much CPU ?

alt text

Helps are greatly appreciated

Thanks

flash1.png (306.6 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Andres-Fernandez · Sep 15, 2014 at 11:01 AM 1
Share

You can just make another object (or as many as you want) follow your player with a small delay in the animation.

Or have objects sampling your player's animation and position and fading out. (use a pool of objects in this case)

avatar image maynull · Sep 15, 2014 at 06:08 PM 0
Share

Any other idea than spawning other objects? Like any options with shaders?

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by robertbu · Sep 16, 2014 at 01:28 AM

Here is some code that uses quads in a mesh rather than individual game objects to create the duplicates. I found the setup fussy and required a trail renderer as well to make things look right. It uses two AnimationCurves...one to define how the duplicates space out, and one to define the transparency. Note the code requires a shader that supports vertex colors. Rather than give a detailed explanation of the setup, you will find a Unity Package here:

www.laughingloops.com/Flash.unitypackage

 using UnityEngine;
 using System.Collections;
 
 public class QuadFollow : MonoBehaviour {
 
     public Material material;
     public int quadCount = 3;
     public AnimationCurve acTransparency;
     public AnimationCurve acSpacing;
     public float spacingFactor = 0.5f;
     public float speed = 12.0f;
 
     private Mesh mesh;
     private float[] lerpingFactor;
     private Vector3[] offsets;
     private Vector3 prevPos;
 
     private Vector3[] vertices;
 
     private Vector3 v0 = new Vector3(-0.5f, 0.5f, 0);
     private Vector3 v1 = new Vector3(-0.5f,-0.5f, 0);
     private Vector3 v2 = new Vector3( 0.5f,-0.5f, 0);
     private Vector3 v3 = new Vector3( 0.5f, 0.5f, 0);
 
     void Start () {
         lerpingFactor = new float[quadCount];
         offsets = new Vector3[quadCount];
 
         for (int i = 0; i < quadCount; i++) {
             lerpingFactor[i] = acSpacing.Evaluate ((float)i / (quadCount - 1.0f)) * speed;
         }
 
         MeshFilter mf = GetComponent<MeshFilter>();
         if (mf == null) {
             mf = gameObject.AddComponent<MeshFilter>();
         }
 
         MeshRenderer mr = gameObject.AddComponent<MeshRenderer>();
         mr.material = material;
 
         mesh = new Mesh();
         mesh.MarkDynamic();
         mf.mesh = mesh;
 
         vertices = new Vector3[quadCount * 4];
         int[] triangles = new int[quadCount * 2 * 3];
         Color[] colors = new Color[quadCount * 4];
         Vector2[] uvs = new Vector2[quadCount * 4];
 
 
 
         for (int j = 0; j < quadCount; j++) {
             vertices[j * 4    ] = v0;
             vertices[j * 4 + 1] = v1;
             vertices[j * 4 + 2] = v2;
             vertices[j * 4 + 3] = v3;
         }
 
         for (int j = 0; j < quadCount; j++) {
             
             triangles[j * 6 + 0] = j * 4 + 0;    //     0_ 3        0 ___ 3
             triangles[j * 6 + 1] = j * 4 + 3;    //   | /         |    /|
             triangles[j * 6 + 2] = j * 4 + 1;    //  1|/            1|/__|2
             
             triangles[j * 6 + 3] = j * 4 + 3;    //       3
             triangles[j * 6 + 4] = j * 4 + 2;    //    /|
             triangles[j * 6 + 5] = j * 4 + 1;    //  1/_|2
         }
 
         for (int j = 0; j < vertices.Length / 4; j++) {
             uvs[j * 4 + 0] = new Vector2(0,1);
             uvs[j * 4 + 1] = new Vector2(0,0);
             uvs[j * 4 + 2] = new Vector2(1,0);
             uvs[j * 4 + 3] = new Vector2(1,1);
         }
 
         Color c = Color.white;
         for (int i = 0; i < quadCount; i++) {
             c.a = acTransparency.Evaluate ((float)i/(quadCount - 1.0f));
             colors[i * 4    ] = c;
             colors[i * 4 + 1] = c;
             colors[i * 4 + 2] = c;
             colors[i * 4 + 3] = c;
         }
 
         mesh.vertices = vertices;
         Debug.Log (vertices.Length);
         mesh.triangles = triangles;
         mesh.colors = colors;
         mesh.uv = uvs;
         mesh.RecalculateNormals();
 
         prevPos = transform.position;
     }
     
     void Update () {
         Vector3 delta = prevPos - transform.position;
         prevPos = transform.position;
         for (int i = 0; i < quadCount; i++) {
             offsets[i] += delta;
             offsets[i] = Vector3.MoveTowards (offsets[i], Vector3.zero, Time.deltaTime * lerpingFactor[i]);
             vertices[i * 4    ] = offsets[i] + v0;
             vertices[i * 4 + 1] = offsets[i] + v1;
             vertices[i * 4 + 2] = offsets[i] + v2;
             vertices[i * 4 + 3] = offsets[i] + v3;
         }
         mesh.vertices = vertices;
     }
 }

If your original object is 2D, it would be possible to fold the display of the original plus the the display of the trail into this code, so the result would be one mesh for everything (original object, duplicates and trail), which would draw in a single draw call.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image maynull · Sep 16, 2014 at 12:04 PM 0
Share

Thanks so much!!! That greatly helps!!

avatar image maynull · Sep 18, 2014 at 11:39 AM 0
Share

How can we horizontally reverse the character? Like when sprite is reversed, followers also reverse

avatar image
0

Answer by Cherno · Sep 16, 2014 at 01:44 AM

There are shaders like the Silhouette Outline one on the Unity Wiki that show a copy of the mesh, maybe you can hack one of these so it shows two or three copies of the mesh offset to the back of the object.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

VHS style tearing effect 0 Answers

Muzzle Flash 1 Answer

How to trace the movement of player animation? 0 Answers

How can I create glowing trail effect? 0 Answers

Trail renderer problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges