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
2
Question by Persona · Nov 03, 2011 at 03:11 PM · rotationmousereferencepivot

How to rotate an object by its pivot in script

I need to rotate an object by its pivot using the mouse input, but I can't seem to find a reference in the Unity Script Reference on rotating by pivots in script. Does anyone know how to do it?

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 Persona · Nov 25, 2011 at 08:34 PM 0
Share

I need to be able to adjust the rotation around the pivot point using the input keys.

3 Replies

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

Answer by GoSuNeem · Nov 03, 2011 at 04:16 PM

As far as I know, I don't think you can set a pivot point.

(I am still fairly new to unity)

But What I do is make a empty game object and put childs in there... Using the parent as a pivot point and rotate that.

Hope that helps. Good luck!

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 kamran-bigdely · Jan 30, 2019 at 08:45 PM 0
Share

This trick works well but if you are making an SD$$anonymous$$ for other programmers or artists, it's not a user-friendly approach.

avatar image
0

Answer by BarkShark · Nov 25, 2011 at 08:43 PM

You can use pivot point in unity, next to the scale tool you see a button 'center' . Hit this button and your object will become a pivot point. I used this and it works perfectly

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 Persona · Nov 26, 2011 at 04:02 PM 0
Share

In editor mode.

I need it to rotate by Pivot through scripting. during gameplay

avatar image
0

Answer by BlurMotions · Sep 02, 2016 at 09:16 AM

You can use this

 private Vector3 object_pos;
     private Vector3 mousePosition;
    
     public float moveSpeed = 0.1f;
     public Transform target; //Assign to the object you want to rotate
     float angle;
 
 
 
     // Use this for initialization
     void Start () {
     }
 
 
 
     void Update () {
         //rotation
         Vector3 mousePos = Input.mousePosition;
         mousePos.z = 5.23f;
 
         Vector3 objectPos = Camera.main.WorldToScreenPoint (transform.position);
         mousePos.x = mousePos.x - objectPos.x;
         mousePos.y = mousePos.y - objectPos.y;
         float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
         transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
 
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 BlurMotions · Sep 02, 2016 at 04:45 AM 0
Share

In unity you can set the pivot on an object.. a 2D sprite, using the inspector when dealing with textures and with 3D You can't change the pivot atleast not directly, but you can create a custom pivot, to do this create an empty GameObject and attach to it whatever GameObject you want to this empty GameObject then from that you can set a pivot point

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotate plane on a pivot to the mouse position (in 2D) 1 Answer

Rotation of Object on single axis in direction of the mouse position 0 Answers

Simple LookAt Rotation with offset pivot 2 Answers

Can I set a custom pivot point for an empty GameObject? 1 Answer

Problem with wheel rotation 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