Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Inan-Evin · Nov 23, 2011 at 07:02 PM · controltank

How to center the rotation point ?

Hello everyone, I'm trying to make a tank control system from birdseye view, and I have some problems. The tank model I'm using is free from the internet, so I can't edit it, I mean I don't know how to deal with 3d model. Anyways, my problem is, when I rotate the model, it rotates to the angles I want but when it does that it changes it's own position, it like it's not rotating from the center, it's rotating from another point. here is a pic about it :

125alt text125

as you can see here, the tank changes it's position according to the position too, I want it to rotate from the center, is there anyway to do that with code or by the editor ?

Here is my rotating code:

 function Update () {
 print (transform.eulerAngles.y);
 
 if (Input.GetKey("w")){
 transform.eulerAngles = Vector3(0, 0, 0);
 transform.Translate(Time.deltaTime*2.5,0,0,Space.World);
 
 }
 
 if (Input.GetKey("a")){
 transform.eulerAngles = Vector3(0, -90, 0);
 transform.Translate(0,0,Time.deltaTime*2.5,Space.World);
 
 }
 
 if (Input.GetKey("d")){
 transform.eulerAngles = Vector3(0, 90, 0);
 transform.Translate(0,0,Time.deltaTime*-2.5,Space.World);
 
 }
 
 if (Input.GetKey("s")){
 transform.eulerAngles = Vector3(0, 180, 0);
 transform.Translate(Time.deltaTime*-2.5,0,0,Space.World);
 
 }
 
 
 }

Thanks :)

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

4 Replies

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

Answer by thorbrian · Nov 23, 2011 at 08:18 PM

The simplest solution without changing the model is to make the model a child gameobject of your tank gameobject (the one that has the script), and position the child gameobject of the model so the rotation point you want is at the origin of the parent tank gameobject with the script. (I actually use that setup as a rule for all scripted objects in Unity even when I don't have origin problems with the model)

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
4

Answer by jmh · Feb 07, 2012 at 02:58 AM

i know this has been answered but i thought id put it out there - i had this problem with a 3d model myself and if you select the model you need to pivot about the center, go into 'gameobject' and click on 'center on children'. simple as, took me a long time :)

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 khrysller · Apr 15, 2020 at 09:38 PM 0
Share

this saved my day. thanks

avatar image
1

Answer by Vienna · Nov 24, 2011 at 09:38 PM

Yeah, I had similar issue. What I did was create an empty object to act as the "pivot point" and position the model within it so that the pivot point is correct. Your script would then control the pivot point (parent). It works for but I also wonder if there is a better, more direct way to specify the pivot center... ?

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
1

Answer by sunwangshu · Apr 28, 2017 at 05:09 AM

I know it's an old thread but really want to share the example here: http://catlikecoding.com/unity/tutorials/clock/

The trick is to have the object you want to move put under an additional parent, set the position of the parent the rotation center you want, then set the localRotation of the parent instead of the child. (important! if not using localRotation it will only rotate in world coordinates instead of local)

The example was having the hierarchy of Clock > Hour > cube, where Clock means the clock face, Hour is the additional parent that rotates, and the Cube is the physical object.

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

7 People are following this question.

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

Related Questions

How to make camera position relative to a specific target. 1 Answer

How to control particle lifetime when emitting programmatically? 1 Answer

How do you rotate an Object without Rotating Raycast 1 Answer

Is it possible to control how the intensity of light decreases with distance? 1 Answer

2D C# Rotation Stopped Working Since Unity 5, Please Help? 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