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 Hariyava · Jun 04, 2014 at 01:12 PM · transformrotaterotatearound

how to rotate game-Object in a fixed position

Hai, I am new to unity.I am developing a project on rotating the Game-Object on its fixed position while swiping.Actually i can rotate the object with "transform.rotateAround" as well as "transform.Rotate" but my problem is my game object its moving from its place while rotating which i dont want.I want it to be stable.I cant figure out the problem.Can any help me with this? I have attached my program below,

pragma strict

var cube:Transform;

function Start () { cube = GameObject.Find("cube").transform; }

function Update () {

 if(Input.touchCount >= 1) {
     if (Input.touchCount == 2 && Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved) {
         var touch1:Touch = Input.GetTouch(0);
         var touch2:Touch = Input.GetTouch(1);

         if(touch1.deltaPosition.x > 0 && touch2.deltaPosition.x > 0) {
             Rotate3DObject(touch1, touch2);
         } else if(touch1.deltaPosition.x < 0 && touch2.deltaPosition.x < 0) {
             Rotate3DObject1(touch1, touch2);
         }
     }
 }

}

function Rotate3DObject(touch1:Touch, touch2:Touch) {

 cube.RotateAround(cube.position,Vector3.up,-touch1.deltaPosition.x);

}

Comment
Add comment · Show 2
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 Scribe · Jun 04, 2014 at 01:18 PM 1
Share

Where is the pivot point in relation to your 'cube' model, If you have imported the model then it could be that the pivot point when imported meaning the cube.position is not centered in your cube. If you are using the builtin primitive cube model from unity then I'm not sure what your problem is. Is the object a child of some other object?

avatar image alcatraz5 · Jun 04, 2014 at 04:31 PM 0
Share

hey try adding torque or angular velocity check scripting reference.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Xtro · Jun 04, 2014 at 07:50 PM

Put your object in another empty gameobject. Move the child object (your object) so its center matches the pivot of the parent object. Add your rotating script to the parent object. That should do it.

If you still see that your object is moving while rotating, try to make it centered with the parent's pivot again.

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 Hariyava · Jun 05, 2014 at 05:45 AM 0
Share

Thanks Xtro :) Ill try it

avatar image JPhilipp · Sep 20, 2016 at 05:40 PM 0
Share

Thank you for this sweet solution

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

25 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

Related Questions

transform RotateAround 1 Answer

rotation script in unity 3 Answers

transform.rotate only 1 time for 180 degrees? 1 Answer

Rotate Around Object 2 Answers

RotateAround help 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