Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RotateTransformInteractor : TransformInteractor
- {
- public Transform trackedObject; //The rotational value to track that will be mapped onto the interactable.(Player Hand)
- private Quaternion trackedObjStartRot; //The starting rotation of the rotational target to track.
- private Quaternion targetStartRot; //The starting rotation of the interactable target to rotate.
- private Vector3 trackedObjStartEuler;
- //Called when pointer hits a valid object.
- internal override void ValidHit(GameObject hit)
- {
- //Save the starting values for the objects.
- trackedObjStartRot = trackedObject.rotation;
- targetStartRot = transformObject.transform.rotation;
- }
- //Called every frame that pointer is over valid object.
- internal override void TransformObject(Vector3 rayPos)
- {
- if (transformObject == null || trackedObject==null) return;
- Quaternion axisQRot = new Quaternion(0,0,0,0);
- Quaternion trackedObjCurrentRot = trackedObject.rotation;
- Vector3 axisVector = Vector3.zero;
- float currentRotFromStart = trackedObjStartRot.z - trackedObjCurrentRot.z; //Hand z rotation from start in quat.
- float currentAngleFromStart = Quaternion.Angle(trackedObjStartRot, trackedObjCurrentRot); //Hand rotation from start in angle.
- switch (activeAxis)
- {
- case AxisManipulation.x:
- axisVector = Vector3.right;
- break;
- case AxisManipulation.y:
- axisVector = Vector3.up;
- break;
- case AxisManipulation.z:
- axisVector = Vector3.forward;
- break;
- default:
- Debug.Log("Transform tool issue: No axis chosen to manipulate.");
- break;
- }
- transformObject.transform.rotation *= Quaternion.AngleAxis(currentRotFromStart * 100* Time.deltaTime, axisVector);
- //Debug.Log("Result: "+result.ToString("#0.0"));
- //Debug.Log("Hand Angle Quat: "+currentRotFromStart.ToString("#0.0")+" Angle: "+ currentAngleFromStart);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement