- Home /
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);
}
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?
hey try adding torque or angular velocity check scripting reference.
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.
Your answer
Follow this Question
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