- Home /
Question by
phygitalmadhouse · Mar 18, 2018 at 05:45 PM ·
rotationrotate objectrotatearoundquaternions
Quaternion reset rotations didnt smooth
Hi mates,
Im really "obsessed"with a reset rotation smothly in a object.
It looks like only reset his position during a frame-frame time.(?????)
Is a 3d object who manages a flying carpet and i want to capture the flying carpet rotation and reset when a oncollisionexit function when the hand of the kinect stops collision. (is for a kinect personal/hoby proyect i work in GameIndustry but as a 3D Artist).
A guy help me a lot but im stuck anyays in this simple coding lines but im not able to understand.
Any help will be appreciate. I can send a Video if needed.
using UnityEngine;
public class RotateOnCollision : MonoBehaviour {
//Object to rotate (player)
public Transform objectToRotate;
public float rotationInty;
public float smooth;
public float speed;
Vector3 objectsOriginalPosition;
Quaternion objectsOriginalRotation;
void Start()
{
objectsOriginalRotation = objectToRotate.transform.rotation;
}
void RecoverPosition()
{
Debug.Log("void recover");
objectToRotate.transform.rotation = Quaternion.Slerp(objectToRotate.rotation, objectsOriginalRotation, Time.deltaTime * speed);
Debug.Log("void recover end");
}
void OnCollisionStay(Collision col)
{
if (col.gameObject.name == "24_Thumb_Right")
{
//rotate y axis
objectToRotate.transform.RotateAround(objectToRotate.transform.position, transform.up, -rotationInty);
//rotate z axis
objectToRotate.transform.Rotate(Vector3.forward * Time.deltaTime * smooth);
}
}
void OnCollisionExit(Collision col)
{
if (col.gameObject.name == "24_Thumb_Right")
{
print("No longer in contact with " + col.transform.name);
RecoverPosition();
}
}
}
Comment
A video would be lovely. I am a bit confused how you want it to work out. So any reference on what object you want this to happen to and what you want to happen would be great
Your answer
![](https://koobas.hobune.stream/wayback/20220612154846im_/https://answers.unity.com/themes/thub/images/avi.jpg)