Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by kevin0228ca · May 26, 2017 at 01:51 PM · meshprojectorsurfaceprojection

What is the best way of drawing/projecting dynamic trajectory on a ground surface

Hi, I am trying to implement an effect where a trajectory/path of a character is drawn/highlighted on the ground.

Something like alt text

where the blue path has the effect of as though being painted on the ground.

For now I want to make a simplified version that take the intersection point of the camera with the ground plane, then color between the lookat intersection and where the camera stands. something like alt text

I think I can use raycast to get the intersections, but I have no idea how to approach drawing on the surface.

I looked at Projector example such as http://hyunkell.com/blog/rts-style-unit-selection-in-unity-5/

But I think Projector uses a pre-defined texture? In my case the path will be dynamically calculated. Should I draw to a Rendertexture then project that Rendertexture?

I think there might also be options such as using Decay or Trail renderer.

Could anyone point me in the direction how this problem should be approached? Thank you.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kevin0228ca · Jun 03, 2017 at 11:30 AM

I implemented a current solution by using two raycasts, one from the camera to find the gaze intersection, and one directly beneath from the camera to find the camera hover position.

Then, from these two vectors, I create a list of TrailSections, and use that to create a Mesh, then I just put some color on the mesh.

This Mesh approach is taken from the Unity Procedural Trail example from Unity

 struct TrailSection
 {
     public Vector3 point;
     public Vector3 upDir;
     public float time;
 }
  
 private void LateUpdate()
 {
      // remove old sections
      while (sections.Count > 0 && now > sections[sections.Count - 1].time + time)
      {
         sections.RemoveAt(0);
      }
     for (int i = 0; i < numSections; i++)
     {
         float fraction = (float)i / (float)numSections;
         Vector3 pos = Vector3.Lerp(hit.point, camerarayhit.point, fraction);
         TrailSection section = new TrailSection();
         section.point = pos;
         if (alwaysUp)
               section.upDir = Vector3.up;
          else
               section.upDir = transform.TransformDirection(Vector3.up);
          section.time = now;
          sections.Insert(0, section);
       }
     Mesh mesh = GetComponent<MeshFilter>().mesh;
     mesh.Clear();
 /*
 generating mesh vertices, uv, colors, tri
 */
  
 // then assign to mesh
     mesh.vertices = vertices;
     mesh.colors = colors;
     mesh.uv = uv;
     mesh.triangles = triangles;
 }

This works somewhat as I can see the trail extending to where the camera is looking at the floor.

However the framerate is decreased from 60 to about 30.

Is it because I am creating and clear meshes on every frame?

Does anyone know a better approach? Thank you.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Project vertices on surface, make a shape 1 Answer

Animating Offset of projector shader 1 Answer

How to create a 3D surface from a 2d array? 1 Answer

A way to "fold" a texture on a mesh? 1 Answer

Decal on a curved surface 2 Answers


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