# Rotating Rigidbodies

Hi, I’m currently creating a gravity switching puzzle game (or atleast starting to create) and I have gotten to the point where I have my player able to change gravity but I want to be able walk around on the surface the gravity changed to. All I need to do is just rotate to a specific quarternion/quarternion.euler but after multiple days looking around and testing I have reached no where. I attempted various methods and so far have ended up with this

``````            function Update ()
{
if (Input.GetMouseButton(0))
{
var hit : RaycastHit;
var ray : Ray = playerCamera.camera.ViewportPointToRay (Vector3(0.5,0.5,0));
if (Physics.Raycast (ray,hit))
{
var incomingVec = hit.point - transform.position;
var refectVec = Vector3.Reflect(incomingVec, hit.normal);
hitPoint = hit.point;
hitNormal = hit.normal;
targetPos = hit.transform.rotation;

GravityNormal (hitNormal);
GravityRotate ();
}

}
}

function GravityRotate ()
{
var orginRot = transform.rotation;
var targRot = targetPos;
rigidbody.isKinematic = true;

for (var t: float = 0.0; t < 1.0; ){
t += Time.deltaTime;
transform.rotation = Quaternion.Slerp(orginRot, targRot, t);
yield; // return here next frame
}

rigidbody.isKinematic = false;
}
``````

There is a few things in there from other parts of the script (it also has all of my movement and gravity stuff) but this is copy pasted everything to do with my rotating part minus a few debug.log’s and comments. It does rotate however once its finished rotating it goes straight back to its original point. As a note I’m using the unity 4.6 beta 17

You are setting the rotation to dstRot after the loop. This is probably (depending on what dstRot is) causing your problems, the fact that it rotates then gets set back. Just remove that line and it should work.

Well the issue was completely opposite to what I thought it was. Firstly I found about Quaternion.LookRotation. And that seems more fitting/easier to use, Secondly I realized the overlying issue was my mousescript was interfering with the rotating. All i do now is just disable the mouse script while it is rotating which was causing the issues with any and all types of rotation. I had it so my player would rotate but the mouselook script was acting strangely so i disabled it and rotation worked perfectly. Here is a simple piece of code for anyone else with the same issue.

``````mouseScript.enabled = false;
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetTransform.rotation, turnSpeed * Time.deltaTime);
``````