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 /
  • Help Room /
avatar image
0
Question by globalenemy · Oct 25, 2015 at 05:39 PM · linerenderercurves

how do i make bezier curve handles dynamic?

first, I don't understand this bezier curve stuff that i am using too much, so if you can show me an easier aproach suitable to my situation, that would be very awesome.

I was out fishing for a tutorial on bezier curves and I eventually found one and I ended up with this script:

     public LineRenderer line;
     public Transform start;
     public Transform end;
     public Transform handle1;
     public Transform handle2;
     
     private float c;
 
     private Vector3 h1;
     private Vector3 h2;
     private Vector3 q0;
     private Vector3 q1;
     
     void Start () {
         q0 = CalculateBezierPoint(c, start.position, handle1.position, handle2.position, end.position);
 
         line.SetVertexCount(100);
         c = 0.0f; //for first curve c is set to 0
         for (int i = 0; i < 99; i++)
         {
             c += 0.01f;
             q1 = CalculateBezierPoint(c, start.position, handle1.position, handle2.position, end.position);
             if (i == 0) line.SetPosition(i, q0);
             line.SetPosition(i + 1, q1);
             q0 = q1;
         }
     }
 
     public Vector3 CalculateBezierPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3) {
 
         float u, uu, uuu, tt, ttt;
         Vector3 p;
 
         u = 1 - t;
         uu = u * u;
         uuu = uu * u;
         tt = t * t;
         ttt = tt * t;
 
         p = uuu * p0;
         p += 3 * uu * t * p1;
         p += 3 * u * tt * p2;
         p += ttt * p3;
 
         return p;
     }

As you might be able to see, this aproach is using 2 handles to calculate the bezier points. (I really don't know if I need that much I only want to have one single curve in my line. This is the part where I think it could be done more easily)

I need to have the handle(s) dynamic. so that the start and end object can move around in the scene and would still have the line connecting them. I tryed around some hours, but I only got straight lines. Wich faced me to another problem that also needs to be addressed..

..My World isn't a plane, but a sphere: http://i.imgur.com/QbuIvCO.png So I need this line to always be outside (around) this sphere.

It also might be necessary to make the LineRenderer Size (VertexCount) dynamic, So I won't run into later performance issues.

I feel like this is too much to ask for or that this isn't the right place. If I should put this into the forums please tell me so. :\

untitled.png (69.1 kB)
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
2
Best Answer

Answer by Statement · Oct 25, 2015 at 06:43 PM

I think you can do this without beziers. All you are doing is mapping a linerenderer around a sphere with Vector3.Slerp.

Example project
SphericalLines.cs

Snap Transforms will position the From and To transforms on the sphere. You may want to turn that off for your game. It's useful for playing around with handles in the editor though. It'll update the LineRenderer in the editor so you see what you do. If you don't want that, remove [ExecuteInEditMode].

Comment
Add comment · Show 7 · 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 globalenemy · Oct 25, 2015 at 07:50 PM 0
Share

Wow, this is (almost) perfect! Thank you so much!

Almost because I might run into problems later when the sphere gets a detailed terrain. But that is far away, so I shouldn't worry about that too much right now.

However there is a small problem. when I open your project, I don't get that line in red. In fact I can't change the color of it at all. It allways stays black.

avatar image Statement globalenemy · Oct 25, 2015 at 07:59 PM 0
Share

Well, change the material to something else :)

avatar image globalenemy Statement · Oct 25, 2015 at 08:01 PM 0
Share

I did that, and in your project the albedo color of the material already is set to be red. however it is always black. In scene and in game view.

Show more comments

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

31 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Create a curve with the mouse at the apex of the curve ? 0 Answers

Making Raycast line visible 2 Answers

Alternative to linerenderer for Tower Defence path display 2 Answers

Drawn line twists and becomes invisible 0 Answers

Line Renderer 2d Follow the edge 0 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