Hi Guys,
I hope you can help me with this: I created a script file attached to each object. When each object pops up, I would like to be able to rotate it when I touch the IPad2 screen. I have created another program with the attached script but with no augmented reality, and it works but when I add the augmented reality libs it doesn't work anymore :(
Many Thanks for the help.
GC.
This is the script:
public var amountToInterpolate: float = 0.5f; private var startQuat: Quaternion; private var targetQuat : Quaternion ; private var offSetQuat:Quaternion ; private var lastRot:Quaternion; private var objectHit: boolean; function Start() { //lastRot = transform.rotation; lastRot = transform.localRotation; } function ShootRay () { var ray: Ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position); var tempQuat : Quaternion = new Quaternion(); //var hit: RaycastHit; var rhit: RaycastHit; if (Physics.Raycast (ray, rhit, 1000.0f)) { objectHit = true; } Debug.Log("ObjectHit: " + objectHit); if(objectHit) { tempQuat.x = ray.GetPoint(10).x;//rhit.point.x; tempQuat.y = ray.GetPoint(10).y;//tempQuat.y = rhit.point.y; tempQuat.z = ray.GetPoint(10).z;//tempQuat.z = rhit.point.z; } return tempQuat; } function Update () { //This is for the MouseDown if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { if(objectHit) startQuat = transform.localRotation;//rotation; offSetQuat = ShootRay() * startQuat; } //This is for MouseUp if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) { lastRot = transform.localRotation;//rotation; objectHit = false; } //This is for the MouseDrag if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { if(objectHit) { Debug.Log("Dragging "); Debug.Log("objectHIT " + objectHit); targetQuat = ShootRay() * offSetQuat; var endQuat: Quaternion = Quaternion.Slerp (startQuat, targetQuat, Time.time * amountToInterpolate); //transform.rotation = endQuat; transform.localRotation = endQuat; startQuat = targetQuat; Debug.Log("name: " + transform.gameObject.name); } } }
Hi,
thank you for that !! It worked also with the RayCast.. but still I don't understand why my version doesn't work :(. My script is attached to each object and I ray cast the position of the touch as they do. Moreover, I compute the quaternion and use the .localRotation which is the same as using the Rotate(....., Space.self). so I don't really get....
would you be so kind if you can use it and see if it works with u?
Many thanks.
GC.:)