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
0
Question by Endless_Aftermath · Feb 28, 2014 at 10:44 PM · rotateverticesprocedural meshcircle

How do I make a rotatable procedural circle in 3d space?

I'm trying to make a plant that grows upward in different variations depending on variable changes within it's script(s). How I've been running it so far is with a game object that starts at point zero, makes 8 vertices in a circle around it, which would be the base of the plant. Next, I would like to move the gameObject upward and rotate it some, then spawn 8 more vertices that will get connected to the first 8 to create the beginnings of a stem.

The problem I'm having, is that I can't get the vertices to spawn in at a rotated angle along with the gameObject...they're flat, on the gameObject origin with no rotation. I believe my problem is that my vertices aren't being created on the gameObject's x,y,z but world relative. How do I rotate the game object and then manifest these points onto th game object's axis?

 void Start () 
     {
                 all of these points are Transforms
         point1 = getPoint(point1,360);
         point2 = getPoint(point2, 45);
         point3 = getPoint(point3, 90);
         point4 = getPoint(point4, 135);
         point5 = getPoint(point5, 180);
         point6 = getPoint(point6, 225);
         point7 = getPoint(point7, 270);
         point8 = getPoint(point8, 315);            
         
     }


 Vector3 getPoint(Vector3 changePoint, int angle)
 {
 float myCos =   position.x +Mathf.Cos( angle * Mathf.Deg2Rad)*radius;
 float mySin =   position.z +Mathf.Sin(angle * Mathf.Deg2Rad)*radius;    
                  
 changePoint.position= new Vector3(myCos,0 , mySin);
 return changePoint;
 }
Comment
Add comment · Show 3
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 Endless_Aftermath · Mar 01, 2014 at 03:19 AM 0
Share

alt text

verticeissue.jpg (33.1 kB)
avatar image Endless_Aftermath · Mar 01, 2014 at 03:25 AM 0
Share

What's Happening: I'm growing a plant. The PlantHead comes from the seed and releases a game object. The game object has 8 vertices that it creates around it. The PlantHead moves on and keeps dropping these game objects. A separate script pieces them together as a mesh and the game objects control the vertices as the plant is growing.

**The Problem: **When I rotate the PlantHead and then it drops a game object, the game object is in the proper rotation, but the vertices are still level...unrotated.

The code above is what I've currently got as the vertex plotter. I suspect the problem lies within the math...perhaps a quaternion issue? I've been searching and working on this for a day or so now.

avatar image robertbu · Mar 01, 2014 at 04:20 AM 0
Share

Added a response to your new drawing to the bottom of my Answer.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Mar 01, 2014 at 01:19 AM

I'm confused some about what you are really asking. Plus I'm not sure where you are going with the points you generate. Build a mesh? Build a plant out of primitive objects? Anyway here is a bit of code that creates rings of spheres. Each ring is rotated by 'offset' from the previous ring. 'divisions' determines how many spheres are in each ring. These rings are built relative to the game object. They start at the game object and are built in the 'up' of the object. In addition, they are made children of the object the script is on, so you can rotate all the spheres as a unit by rotating the parent game object.

To use, create a new scene, create an empty game object. Position the empty game object at (0,-1.5,0), add a directional light to the scene (Game Object > Create Other > Directional Light), add the following script, and hit play:

 using UnityEngine;
 using System.Collections;
 
 public class Circles : MonoBehaviour {
 
     private float offset = 3.0f;
     private float segHeight = 0.35f;
     private float radius = 1.25f;
     private float divisions = 16;
 
     void Start () 
     {
         float angle = 360.0f / divisions;
 
         for (int i = 0; i < 15; i++) {
             for (int j = 0; j < divisions; j++) {
                 GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                 go.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                 Vector3 pos = GetPoint(j * angle + offset * i, segHeight * i);
                 go.transform.position = transform.TransformPoint (pos);
                 go.transform.parent = transform;
             }
         }
     }
     
     Vector3 GetPoint(float angle, float z)
     {
         float myCos =   Mathf.Cos( angle * Mathf.Deg2Rad)*radius;
         float mySin =   Mathf.Sin(angle * Mathf.Deg2Rad)*radius;    
          
         return new Vector3(myCos,z , mySin);
     }
 }
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 robertbu · Mar 01, 2014 at 04:19 AM 0
Share

Ahhh now I understand your question given your new drawing. The fix is pretty simple. You need to access the transform of your cube/seed. Given that you are adding the position to your calculation, I'm going to assume that this script is on the object that is rotated. The approach is to generate local coordinates then use Transform.TransformPoint() to convert them into world positions. This takes into account, position, rotation, and scale of the object that has the transform. You may have to increase your radius if your 'cube/seed' object is not scaled to (1,1,1), and if you change the scale of your 'cube/seed' object dynamically, you will have to modify the 'radius' dynamically. So here is the change to your code:

 Vector3 GetPoint(float angle)
 {
     float myCos =  $$anonymous$$athf.Cos(angle * $$anonymous$$athf.Deg2Rad) * radius;
     float mySin =  $$anonymous$$athf.Sin(angle * $$anonymous$$athf.Deg2Rad) * radius;    
 
     Vector3 v = new Vector3(myCos, 0.0f, mySin);
     return transform.TransformPoint(v);
 }

As an alternate you could use just rotation and position of the object. Another version (untested) where you don't have to deal with scale:

 Vector3 GetPoint(float angle)
 {
     float myCos =  $$anonymous$$athf.Cos(angle * $$anonymous$$athf.Deg2Rad) * radius;
     float mySin =  $$anonymous$$athf.Sin(angle * $$anonymous$$athf.Deg2Rad) * radius;    
 
     Vector3 v = new Vector3(myCos, 0.0f, mySin);
     v = transform.rotation * v;
     return transform.position + v;
 }
avatar image Endless_Aftermath · Mar 01, 2014 at 04:59 AM 0
Share

Dude! Thank you! That's all it was! I've been going crazy trying to figure this out. Thank you so much. Now that this is figured out, I should have a model of this thing up and running soon. I'll send you a link to it in here. I tried to hit the thumbs up over there on the side but it says I don't have a large enough reputation to tell you good job and thank you through a green thumb. Thank you so much for your help.

avatar image robertbu · Mar 01, 2014 at 05:15 AM 0
Share

Rather than thumbs up, when your questions is answered, click on the checkmark. This closes the question out and you will see the icon on the question list as green.

avatar image Endless_Aftermath · Mar 01, 2014 at 03:11 PM 0
Share

Got it. Now I know. Thanks again.

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

20 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

Related Questions

[Solved] Issues mapping procedurally generated cube without repeating vertices 0 Answers

Holes in procedural mesh 0 Answers

Performance increase by unused Vertices? 1 Answer

How can i draw a circle pie? 2 Answers

Set vertex positions aligned to a grid 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