• 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
0
Question by jrdoda · Jul 28, 2014 at 08:18 PM · linerenderertron

How to add colliders to Tron Like Trail

Hi

I am using the TronTrail script that you can download off unity, but i am trying to add colliders to it to be used in my top down (but uses 3d colliders) racing game where the trails come out the backs of the cars (like tron) and are able to deal damage to the enemy. I am wondering if anyone knows what i need to do. I have searched google and found some answers but they are too advanced for me.

Thanks the code

 /*
  Generates a trail that is always facing upwards using the scriptable mesh interface.
  vertex colors and uv's are generated similar to the builtin Trail Renderer.
  To use it
  1. create an empty game object
  2. attach this script and a MeshRenderer
  3. Then assign a particle material to the mesh renderer
 */
 var height = 2.0;
 var width = 5.0;
 var time = 2.0;
 var alwaysUp = false;
 var minDistance = 0.1;
 
 var startColor = Color.white;
 var endColor = Color (1, 1, 1, 0);
 
 class TronTrailSection
 {
     var point : Vector3;
     var upDir : Vector3;
     var time : float;
 }
 
 private var sections = new Array();
 
 function LateUpdate () {
     var position = transform.position;
     var now = Time.time;
 
     // Remove old sections
     while (sections.length > 0 && now > sections[sections.length - 1].time + time) {
         sections.Pop();
     }
 
     // Add a new trail section
     if (sections.length == 0 || (sections[0].point - position).sqrMagnitude > minDistance * minDistance)
     {
         var section = TronTrailSection ();
         section.point = position;
         if (alwaysUp)
             section.upDir = Vector3.up;
         else
             section.upDir = transform.TransformDirection(Vector3.up);
         section.time = now;
         sections.Unshift(section);
     }
     
     // Rebuild the mesh
     var mesh : Mesh = GetComponent(MeshFilter).mesh;
     mesh.Clear();
     
     // We need at least 2 sections to create the line
     if (sections.length < 2)
         return;
 
     var vertices = new Vector3[sections.length * 2];
     var colors = new Color[sections.length * 2];
     var uv = new Vector2[sections.length * 2];
     
     var previousSection : TronTrailSection = sections[0];
     var currentSection : TronTrailSection = sections[0];
 
     // Use matrix instead of transform.TransformPoint for performance reasons
     var localSpaceTransform = transform.worldToLocalMatrix;
 
     // Generate vertex, uv and colors
     for (var i=0;i<sections.length;i++)
     {
         previousSection = currentSection;
         currentSection = sections[i];
         // Calculate u for texture uv and color interpolation
         var u = 0.0;        
         if (i != 0)
             u = Mathf.Clamp01 ((Time.time - currentSection.time) / time);
         
         // Calculate upwards direction
         var upDir = currentSection.upDir;
         
         // Generate vertices
         vertices[i * 2 + 0] = localSpaceTransform.MultiplyPoint(currentSection.point);
         vertices[i * 2 + 1] = localSpaceTransform.MultiplyPoint(currentSection.point + upDir * height);
         
         uv[i * 2 + 0] = Vector2(u, 0);
         uv[i * 2 + 1] = Vector2(u, 1);
         
         // fade colors out over time
         var interpolatedColor = Color.Lerp(startColor, endColor, u);
         colors[i * 2 + 0] = interpolatedColor;
         colors[i * 2 + 1] = interpolatedColor;
     }
 
     // Generate triangles indices
     var triangles = new int[(sections.length - 1) * 2 * 3];
     for (i=0;i<triangles.length / 6;i++)
     {
         triangles[i * 6 + 0] = i * 2;
         triangles[i * 6 + 1] = i * 2 + 1;
         triangles[i * 6 + 2] = i * 2 + 2;
 
         triangles[i * 6 + 3] = i * 2 + 2;
         triangles[i * 6 + 4] = i * 2 + 1;
         triangles[i * 6 + 5] = i * 2 + 3;
     }
 
     // Assign to mesh    
     mesh.vertices = vertices;
     mesh.colors = colors;
     mesh.uv = uv;
     mesh.triangles = triangles;
 }
 
 @script RequireComponent (MeshFilter)
 
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Getting Error Object reference not set to an instance of an object 1 Answer

Trap Door Question 1 Answer

what's wrong with this script? 2 Answers

Need help syntax error 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