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 /
avatar image
0
Question by RurouniKen · Aug 06, 2019 at 08:29 PM · transform2d gametransform.positionrotate objectrotatearound

Transform Position X/Y increasing by no reason

So yeah my X and Y coordinates of the transform component are moving by their own when my script is supposed to be rotating and object around other only...

I set the value of rotateSpeed inside the inspector, its currently 4.5

 public class CoreOrbitMovement : MonoBehaviour
 
 {
     [Header("RotateAround")]
     private Rigidbody2D myRigidBody;
     public float rotateSpeed;
     private float moveInput;
     
     private Vector3 zAxis = new Vector3 (0,0,1);
 
     public Transform target;
 
 
    
    
     void Start()
     {
         myRigidBody= GetComponent<Rigidbody2D>();
        
     }
 
     // Update is called once per frame
     void Update()
     {   
        
  
         moveInput= Input.GetAxisRaw("RightStickHorizontal");
      
    
        
         RotateChar();
 
     }
 
     public void RotateChar() {
 
        
        transform.RotateAround(target.position, zAxis, moveInput * rotateSpeed);
 
        transform.rotation = target.rotation;
 
   
     }
 
 }
   
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

· Add your reply
  • Sort: 
avatar image
0

Answer by gulle909 · Aug 06, 2019 at 09:36 PM

The function "Rotate Around" is used for moving the GameObject around another GameObject. Im not quite sure what you are trying to achieve, but if you want the GameObject to rotate around itself on the z-axis, you can use this bit of code instead:

 public void RotateChar() {
    transform.Rotate(Vector3.forward * rotateSpeed * moveInput * Time.deltaTime, Space.Self);
 }
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 RurouniKen · Aug 09, 2019 at 04:09 PM

Thanks for taking your time to help me @gulle909.

I'm trying to make an object rotate around another in the Z axis every time I rotate my right joystick. So far I have only made it work whenever I push my joystick to the right or to the left. So is it better to use Transform.Rotate instead of Transform.RotateAround?

Comment
Add comment · Show 2 · 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 gulle909 · Aug 11, 2019 at 01:05 PM 0
Share

But when it's only around the Z axis, why, and how, would you want to rotate it when the joystick gets pushed in any direction?

avatar image RurouniKen gulle909 · Aug 16, 2019 at 08:57 PM 0
Share

I'm making a 2D game, thats why I want to rotate an object around another on the Z axis with the motion of my right joystick so If I rotate my joystick to the right (like doing a half circle motion) my object rotates in that motion around the other.

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

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

RotateAround object around player when pushing button. 1 Answer

How to find a transform with name in prefab 2 Answers

AddMixingTransform not working 0 Answers

Getting Transform position using mouse position 3 Answers

Getting the transform from a GameObject list 3 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