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 anonimogk · Mar 30, 2021 at 02:44 PM · rotatearound

I wanna use rotateAround but up to 45 degrees

I wanna rotate my object around an edge object but it doesnt stop. its x rotation reach 180 and move on like -179, -178.. and make a circle like this. But I want to rotate it up to 45 degrees and back to 0 degrees again in a loop. here is my code part ; obj.transform.RotateAround(edgePoint.transform.position, vec, 20 * Time.deltaTime);

image of my object

1.png (99.7 kB)
Comment
Add comment · Show 1
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 anonimogk · Mar 30, 2021 at 02:49 PM 0
Share

matf.pingpong is used in Quaternion.Euler() like obj.transform.position = new Vector3(Mathf.PingPong(Time.time * 2, max - $$anonymous$$) + $$anonymous$$, obj.transform.position.y, obj.transform.position.z); but it rotates whole object. I need the rotateAround version of it but I am so new at unity and couldnt figure out how to do it :(

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DrTomato · Mar 30, 2021 at 05:36 PM

You normally need to change the pivot point in a 3D modelling application to have your model to rotate around a certain point.

Alternatively, in Unity you can create an empty game object and position it at the point you want to rotate around and then make the object you want to rotate a child of the new empty object. Now rotate the parent object using Quaternion.Lerp or if you want to use euler angles there is a solution here https://answers.unity.com/questions/643141/how-can-i-lerp-an-objects-rotation.html

Edit: The link wasn't intended as a full answer but to direct you to information to piece together a solution yourself. I have included a more direct solution below.

 IEnumerator LerpRotation(Vector3 rotationAmount, float duration)
     {
         print("Start");
         float time = 0;
         Vector3 startRotation = transform.rotation.eulerAngles;
         Vector3 targetRotation = startRotation + rotationAmount;
 
         while (time < duration)
         {
             print(Vector3.Lerp(startRotation, targetRotation, time / duration));
             transform.rotation = Quaternion.Euler(Vector3.Lerp(startRotation, targetRotation, time / duration));
             time += Time.deltaTime;
             yield return null;
         }
         time = 0;
         while (time < duration)
         {
             transform.rotation = Quaternion.Euler(Vector3.Lerp(targetRotation, startRotation, time / duration));
             time += Time.deltaTime;
             yield return null;
         }
         transform.position = startRotation;
         print("End");
     }

This can be started using

 StartCoroutine(LerpRotation(new Vector3(0, 45, 0), 1));

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 anonimogk · Mar 30, 2021 at 06:45 PM

@DrTomato the link you shared is just about rotating an object from current rotation to a value. It doesnt work in a loop. " I want to rotate it up to 45 degrees and back to 0 degrees again in a loop. "

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

114 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

Related Questions

Rotate around using another objects axis 1 Answer

Accouting for random rotations in Rotate Around 1 Answer

TPS Rotation Camera (similar to WoW or any other mmo) 0 Answers

How can I change SpringJoint2D's anchor points in script? 1 Answer

Rotate object around certain point using phyics 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