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