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 PeacefuImind · Jun 01, 2021 at 09:04 PM · transform.rotatearound

transform.RotateAround does not rotate to the object I want

Hi guys i have a problem with transform.RotateAround and I hope that you could help me out. I want my GameObject(which is attached to the script) to rotate around an object with a OnTriggerStay function. I made another object, so when he triggers with that my GameObject will rotate around the object i want, but instead it rotates around the object it triggers with. Any Idea ? Here is my code (I dont move my GameObject via Script at the moment i do it manually on the playmode):

 public class Player : MonoBehaviour
 {
     [SerializeField]
     GameObject target;
     bool rotate = true;

     void FixedUpdate()
     {
         Launch();
     }

     void Launch()
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             rotate = false;
         }
     }

     void OnTriggerEnter(Collider other)
     {
         if (other.tag == "Planet")
         {
             Destroy(gameObject);
         }
     }

     void OnTriggerStay(Collider other)
     {
         if (other.tag == "PerfectLanding" && rotate == true)
         {
             transform.RotateAround(target.transform.position, Vector3.up, 200 * Time.deltaTime);
         }
     }
 }
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 chubshobe · Jun 01, 2021 at 09:51 PM 0
Share

I can't see an issue with your code, maybe there's another behaviour somewhere that's affecting the transform and causing the unexpected behavior.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Jun 01, 2021 at 11:31 PM

You probably set the target to reference the trigger instead the object you want to rotate around. I tested your code and I couldn't see any problem with it.

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 PeacefuImind · Jun 03, 2021 at 05:24 PM 0
Share

The things that exists in the scene are the following :

  • sphere (the GameObject with the tag "Planet" and also the target on the script) and extra components a rigidbody with no gravity and it's sphere collider triggered

  • capsule(the GameObject with the tag "Player") and extra components a rigidbody with no gravity, the script above and its capsule collider triggered.

  • cube(the GameObject with the tag "PerfectLanding") with its box collider triggered and its mesh renderer unchecked.

So what I want to do is when the capsule triggers with the cube, the capsule should RotateAround the sphere(the target), but instead it rotates around the cube.

I hope this made it more clear to what my problem is and i hope you can help me out.

Reply me or not, thank you for your time.

avatar image
0

Answer by PeacefuImind · Jun 03, 2021 at 03:20 PM

The target is the GameObject i want to rotate around, but instead it rotates around the GameObject that it is being trigger. I can not see any mistake to my code or in the scene as well, that is why I am so confused.

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

120 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

Related Questions

Issue understanding transform.RotateAround,Questions regarding transform.RotateAround 0 Answers

Rotate around moves object out of position, why? 1 Answer

Can you simulate the behavior of Transform.RotateAround using a Rigidbody? 0 Answers

Wheels that just plain won't spin 0 Answers

How to limit the rotation of an object 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