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 spinnerbox · Sep 24, 2015 at 01:08 PM · linerendererlinecastbeziercurved path

Make a dynamic visual link between two game objects

I have two ships and a planet in between. I want to make a visual link between the ships but in a way that the link will arc around the planet, but not trough it.

I also want this to be dynamic, for example when I select one of the ships and move it with arrow keys. I want the line link to adapt and change to the new position of the ship dynamically.

I thought maybe LineRenderer but that is just a straight line. Any ideas how can I achieve this is unity? Is there some component that I could possibliy use and adapt to this scenario?

thanks.

dynamic line link between game objects

lines.png (9.5 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
3
Best Answer

Answer by cjdev · Sep 24, 2015 at 09:46 PM

While the line renderer only renders straight lines between two points it can render an arbitrary amount of them in succession between different points. This allows you to render a curve with a resolution dependent on the number of line segments in your renderer.

To set a curve like the one in your picture you'd be much better off splitting it into two curves, one that goes to the high point above the planet and one that continues to the next ship. Using a curve equation of your choice, my personal favorite is the Bezier equation, you can then get the positions of each of the vertices that goes into your SetPostion LineRenderer method. If you're not familiar with it, a Bezier curve consists of 4 points: the beginning and end plus a control point for each that determines the curve and direction the curve begins and ends at each point. It looks something like this:

alt text

Where 0 and 3 are the beginning and end, 1 is the control point for the beginning and 2 for the end. The control points effectively pull the curve in their direction so they can be adjusted depending on how you need the curve to look accordingly. The code for it is surprisingly simple:

 private Vector3 Bezier(float t)
 {
     float mt = 1 - t;
     float x = mt * mt * mt * bezierPoints[0].x + 3 * mt * mt * t * bezierPoints[1].x + 3 * mt * t * t * bezierPoints[2].x + t * t * t * bezierPoints[3].x;
     float y = mt * mt * mt * bezierPoints[0].y + 3 * mt * mt * t * bezierPoints[1].y + 3 * mt * t * t * bezierPoints[2].y + t * t * t * bezierPoints[3].y;
     float z = mt * mt * mt * bezierPoints[0].z + 3 * mt * mt * t * bezierPoints[1].z + 3 * mt * t * t * bezierPoints[2].z + t * t * t * bezierPoints[3].z;
     return new Vector3(x, y, z);
 }

This will get you a Vector3 at a percentage 0 - 1.0f along the bezier curve defined by the list bezierPoints with indices of points like those shown in the picture above. So to make your line renderer into a curve you would use SetPosition and iterate over your total points with something like Bezier(i / totalPoints).


bezier.png (17.9 kB)
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

28 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

Related Questions

Create a line renderer along a Bezier Curve/ Spline 0 Answers

Find Vector3 point exactly between two gameobjects with an offset perpendicular to the line connecting the two gameobjects 1 Answer

Move along a run-time generated path of varying length at a set speed. 1 Answer

How to get a LineRenderer to shoot from Gun Point to Mouse Position 1 Answer

Bezier curver using LineRenderer 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