Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Sep 18, 2020 at 06:03 PM by ugurgulser for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ugurgulser · Sep 18, 2020 at 02:41 PM · rotatecircletriangles

Rotate Triangles "Correctly" Around The Circle

Hello,

I have a circle and this circle has orbits around it. The orbits' shape is triangle.

alt text

My orbit creation code:

 public void CreateOrbitsAroundCircle(int num, Vector3 point, float radius)
     {
 
         for (int i = 0; i < num; i++)
         {
 
             /* Distance around the circle */
             var radians = 2 * Mathf.PI / num * i;
 
             /* Get the vector direction */
             var vertical = Mathf.Sin(radians);
             var horizontal = Mathf.Cos(radians);
 
             var spawnDir = new Vector3(horizontal, vertical, 0);
 
             /* Get the spawn position */
             var spawnPos = point + spawnDir * radius; // Radius is just the distance away from the point
 
             /* Now spawn */
             var newOrbit = Instantiate(orbit, spawnPos, Quaternion.identity, this.transform);
 
             //newOrbit.name = playerName;
 
             /* Rotate the enemy to face towards player */
             //enemy.transform.LookAt(point);
 
             /* Adjust height */
             //enemy.transform.Translate(new Vector3(0, enemy.transform.localScale.y / 2, 0));
         }
     }

I can add orbits by this code up to 10 orbits.

My question is this: I want to rotate triangles like my circle has spikes! Like this: alt text

How can I do that?

unityask.jpg (13.8 kB)
unityask4.jpg (11.0 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

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by ugurgulser · Sep 18, 2020 at 06:02 PM

I just added this code to orbits. It worked well!

 target = transform.parent.gameObject;
 Vector3 dir = target.transform.position - transform.position;
 float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
 transform.rotation = Quaternion.AngleAxis(angle + 90, Vector3.forward);

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

Answer by unity_ek98vnTRplGj8Q · Sep 18, 2020 at 03:30 PM

First make sure your triangle prefab is pointing up. This will make it easy to calculate the rotation to apply to the triangle if we already know the rotation of the prefab before we spawn it. Then you just need to calculate the angle to rotate your triangle by depending on where on the circle you are going to place it. You can do that by calculating the angle between the up direction and the direction of your spawn position.

 var spawnPos = point + spawnDir * radius; // Radius is just the distance away from the point
 
 float rotAngle = Vector3.Angle(Vector3.Up, spawnDir);
 if(spawnDir.x < 0) rotAngle *= -1;
 Quaternion orbitRotation = Quaternion.Euler(0, 0, rotAngle);
 /* Now spawn */
 var newOrbit = Instantiate (orbit, spawnPos, orbitRotation, this.transform);
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 ugurgulser · Sep 18, 2020 at 05:27 PM 0
Share

Thanks for your reply.

This code works well with one,two,three and six orbits. When it comes four orbits or more. It gets weird. Can you help me?

alt text alt text

unityask6.jpg (10.5 kB)

Follow this Question

Answers Answers and Comments

139 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

Related Questions

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

Rotating guiTexture around a point in circle 0 Answers

Camera rotation around player while following. 6 Answers

Advance Unity 2d apply circle Rotation-z with mouse 1 Answer

Spin a texture in just any material -is it possible? 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