- Home /
Problems with the axes of the object
Hello! Sorry for my english im from ukraine, is the object that you want to turn on its axis, but the axis is slightly angled. I object turns like this: video. But we need to properly scrolled =) like so: video.Here is my script for the scroll object:
public class RevolverScript : MonoBehaviour {
private float rotate_y ;
public float spin_speed = 100;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("left")) {
print("left");
rotate_y +=(spin_speed * Time.deltaTime);
}
if (Input.GetKey ("right")) {
print ("right");
rotate_y -=(spin_speed * Time.deltaTime);
}
rotate_y = rotate_y%360.0f;
this.transform.rotation = Quaternion.Euler(0, rotate_y, 0);
}
I tried to edit the pivot and still trying to shove my object in perfab. But this is not all useful, I do not know what to do. It seems to me that it does not really do. Please help as many races have tried to make himself but without success.Link for downloat this project.rar
Answer by le_duke · Mar 18, 2014 at 09:39 PM
You are using this.transform.rotation this is giving you the rotation of your gameobject using the world coordinates rotation.
you need to use Transform.localRotation in order to get the rotation axis relative to your gameobject.
http://docs.unity3d.com/Documentation/ScriptReference/Transform-localRotation.html
so a working code should be like :
public class RevolverScript : MonoBehaviour {
private float rotate_y ;
public float spin_speed = 100;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("left")) {
print("left");
rotate_y +=(spin_speed * Time.deltaTime);
}
if (Input.GetKey ("right")) {
print ("right");
rotate_y -=(spin_speed * Time.deltaTime);
}
rotate_y = rotate_y%360.0f;
this.transform.localRotation = Quaternion.Euler(0, rotate_y, 0);
}
thenks for answer, but its not work. I think can also try to use RotateAround, but also that it does not work: this.transform.RotateAround(cube.transform.position, Vector3.up, 90 * Time.deltaTime); $$anonymous$$aybe I'm doing something wrong with the coordinates?
it helped me: this.transform.Rotate(Vector3.up, Time.deltaTime * 90);
Your answer
![](https://koobas.hobune.stream/wayback/20220613140608im_/https://answers.unity.com/themes/thub/images/avi.jpg)