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 OGNE · Oct 11, 2018 at 06:41 AM · effects

Create a Octagon using line renderer. What could be the perfect X,Y numric values for doing this?

Hey guys need to create a Regular Octagon using Line renderer so what could be the perfect X,Y position numeric values for doing so.. I was able to create a hexagon by watching brackeys video..but octagon is much more complex. Any help would be appreciated?

Comment
Add comment · Show 2
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 NoDumbQuestion · Oct 11, 2018 at 06:56 AM 0
Share

math + google http://mathcentral.uregina.ca/QQ/database/QQ.09.06/h/brady1.html

avatar image OGNE · Oct 11, 2018 at 09:00 AM 0
Share

I have created a octagon by editing the points and using mouse and some maths..but without codealt text

octa.jpg (74.0 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Hellium · Oct 11, 2018 at 07:09 AM

What have you tried so far?

I don't believe it's way more complex....

With the following code, you can have any regular shape you want:

     public LineRenderer lineRenderer;

     [Range(3, 20)]
     public int positionsCount;

     [Range(1, 10)]
     public float radius;

     [Range(0, 360)]
     public float rotation;

     public Vector3 normal = Vector3.forward;

     [ContextMenu("OnValidate")]
     private void OnValidate()
     {
         lineRenderer.positionCount = positionsCount;
         Vector3[] positions = GetPoints( lineRenderer.positionCount, radius, rotation * Mathf.PI / 180f, normal ).ToArray();
         lineRenderer.SetPositions( positions );
     }

     public List<Vector3> GetPoints( int sides, float radius, float rotation = 0 )
     {
         return GetPoints( sides, radius, rotation, Vector3.forward );
     }

     public List<Vector3> GetPoints( int sides, float radius, float rotation, Vector3 normal )
     {
         List<Vector3> points = new List<Vector3>( sides ) ;
         float angle = 0 ;
         normal.Normalize();
         Vector3 right = Vector3.Cross( normal, Vector3.up ).normalized;
         Vector3 up = Vector3.Cross( normal, right ).normalized;

         if ( sides <= 1 )
         {
             points.Add( new Vector3( 0, 0 ) );
         }
         else
         {
             for ( int sideIndex = 0 ; sideIndex < sides ; sideIndex++ )
             {
                 Vector3 point = up * Mathf.Cos( angle + rotation ) * radius + right * Mathf.Sin( angle + rotation ) * radius;
                 points.Add( point );
                 angle += Mathf.PI * 2f / sides;
             }
         }

         return points;
     }

     private void OnDrawGizmos()
     {
         Gizmos.DrawLine( lineRenderer.transform.position, lineRenderer.transform.position + normal.normalized );
     }
Comment
Add comment · Show 1 · 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 Hellium · Oct 16, 2018 at 10:16 AM 0
Share

@VIRI$$anonymous$$O Did this script work for you?

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

154 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 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 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 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 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

Looking for 2d filters: glow, dropshadow, outline, etc. 0 Answers

How to make water flow and take up volume 0 Answers

How can I make an impact distortion effect? (Unity 2D),Impact distortion effect 0 Answers

Leaving sprite shadow-like behind on Dash 0 Answers

Projectile Effects 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