- Home /
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 :
125125
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 :)
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)
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 :)
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... ?
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613052951im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Animating Tank Treads 0 Answers
firing a shell from a tank turret 1 Answer
Multiplayer projectiles collision 0 Answers
player on trigger enter dont work? 1 Answer