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 Aggressor · Mar 07, 2015 at 10:15 PM · pathfindinglinerendererlinerealtimeastar

Smooth out a line renderer

Greetings,

I really love the arrow system in this game, Gettysburg Ultimate General

alt text

Particularly the way the blue arrow is curving, its really smooth and it adapts to the path you draw.

I am trying to create a similar system using A* and the Line Renderer. I create a path, and then put those points into the Line Renderer. As you can imagine, the turns come out jagged, and no where near smooth:

alt text (My Attempt)

My question is: Can I make my line smooth with the line renderer or is there another technique should be using? I'd love to recreate the arrows as seen above.

path.png (11.6 kB)
Comment
Add comment · Show 1
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 fafase · Mar 07, 2015 at 10:28 PM 0
Share

http://answers.unity3d.com/questions/917707/draw-a-cruved-line.html

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Cherno · Mar 07, 2015 at 10:25 PM

Look into Bezier curves, It's mostly (relatively) simple maths, I bet there are tons of examples for calculating coordinates for additional points on a line that should curve in a certain way. Then, it's just a way of deciding how many segments you want to have. If you don't want to go all-in with Bezier curves, you can always use simple terms like y = x² and derivatives to find out which y height a certain point should have along a line from source to target. Ther are online calculators for this, as well, with plooting features that show how your graph will look like with any given function.

Comment
Add comment · Show 4 · 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 Aggressor · Mar 07, 2015 at 11:23 PM 0
Share

$$anonymous$$y thanks I will take a look at this.

avatar image Cherno · Mar 08, 2015 at 12:39 AM 1
Share

Here's a script way back when I was still using UnityScript, I used it do draw indicator lines for grenade throwing arcs and explosion radii with a LineRenderer. The script is supposed to go onto a Game $$anonymous$$anager, Utility type of gameObject that just sits at 0,0,0 and never moves (which would maybe hold other scripts that manage your game, like time and so on). The "coverValue" float in the throwing arc function is just a value from 0 to 100, I uses it to change the color of the arc line from green to yellow to red depending on how much soft and hard cover there was intersecting the arc. You can ignore it / set it too 0 if you want.

avatar image Cherno · Mar 08, 2015 at 12:39 AM 1
Share
 function DrawCircle(pos1 : Vector3, radius : float)
 {
     var vertexCount : int;
     if(radius < 6)
     {
         vertexCount = 2 * $$anonymous$$athf.PI * radius * 2;
     }
     else
     {
         vertexCount = 2 * $$anonymous$$athf.PI * radius / 2;
     }
      
     var lineRenderer : LineRenderer = GetComponent(LineRenderer);
     var c1 : Color = Color(1.0, 1.0, 1.0, 0.5);
     //lineRenderer.material = new $$anonymous$$aterial(Shader.Find("Particles/Additive"));
     lineRenderer.SetColors(c1, c1);
     lineRenderer.SetWidth(0.05, 0.05);
     lineRenderer.SetVertexCount(vertexCount + 1);//+1 so the last point gets connected to the first one
     
     var deltaTheta : float = (2.0 * $$anonymous$$athf.PI) / vertexCount;
     var theta : float = 0;
      
     for (var i : int = 0; i < vertexCount + 1; i++)
     {
         var x : float = radius * $$anonymous$$athf.Cos(theta) + (pos1.x - transform.position.x);//works only if the the pos1 x and z values are positive (GameController has to stay at (0,0,0))
         var y : float = transform.position.y - pos1.y + 0.1;
         var z : float = radius * $$anonymous$$athf.Sin(theta) + (pos1.z - transform.position.z);
         var pos : Vector3 = new Vector3(x, y, z);
          
         lineRenderer.SetPosition(i, pos);
          
         theta += deltaTheta;
     }
 }
 
 function DrawThrowingArc(pos1 : Vector3, pos2 : Vector3, coverValue : float)
 {
     var hitlineColor : Color;
     hitlineColor.r = coverValue / 100;
     hitlineColor.g = 1.0 - (coverValue / 100);
     hitlineColor.b = 0.0;
     hitlineColor.a = 0.5;
 
     var lineRenderer : LineRenderer = GetComponent(LineRenderer);
 
     var sections : float = 5.0 + $$anonymous$$athf.Round(Vector3.Distance(pos1, pos2)); // should be float for division purposes
     lineRenderer.SetVertexCount(sections);
     
     var t : float ;    
 
     for (var i : int = 0 ; i < sections ; i++ )
     {
          t = i/(sections - 1) ;
          lineRenderer.SetPosition (i, GetQuadraticCoordinates(t, pos1 + Vector3.up * 1.4, Vector3.Lerp(pos1, pos2, 0.5) + Vector3.up * (Vector3.Distance(pos1, pos2) / 2.0), pos2 + Vector3.up * 0.1));
     }
 
     lineRenderer.SetWidth(0.05,0.05);
     lineRenderer.SetColors(hitlineColor, hitlineColor);
     
     lineRenderer.enabled = true;
 }
 
 function GetQuadraticCoordinates(t : float , p0 : Vector3 , c0 : Vector3 , p1 : Vector3 ) : Vector3 
 {
     return $$anonymous$$athf.Pow(1 - t, 2) * p0 + 2 * t * (1 - t) * c0 + $$anonymous$$athf.Pow(t, 2) * p1;
 }
avatar image Aggressor · Mar 08, 2015 at 01:47 AM 0
Share

Epic thanks!

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

22 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

Related Questions

How do i get the IsPathPossible() function to ignore some nodes using Astar Pathfinding Project 0 Answers

Implementation of Navmesh terrain dijkstra algorithm 0 Answers

LineRenderer with nontrivial radius? 1 Answer

Draw a line to a new pontential character position/target 1 Answer

Linerenderer Inconsistency 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