Hi All,
I am making a simple projectile motion. my same requirement is
http://phet.colorado.edu/sims/projectile-motion/projectile-motion_en.html
As above link, For that i have take one cannon maya object and added boxcollider and one empty game object for pivot. I have added this script but I can’t able to drag my object. how can fix that?
my code is like this:(from forms only i got code)
using UnityEngine;
using System.Collections;
public class DragRotate : MonoBehaviour {
public Transform pivot;
private float angle;
private Vector3 v3Pivot; // Pivot in screen space
void Start () {
v3Pivot = Camera.main.WorldToScreenPoint (pivot.position);
}
void OnMouseDown() {
Vector3 v3T = (Vector3)Input.mousePosition - v3Pivot;
angle = Mathf.Atan2 (v3T.y, v3T.x) * Mathf.Rad2Deg;
}
void OnMouseDrag() {
Vector3 v3T = (Vector3)Input.mousePosition - v3Pivot;
float angleT = Mathf.Atan2 (v3T.y, v3T.x) * Mathf.Rad2Deg;
float angleDiff = Mathf.DeltaAngle(angle, angleT);
pivot.Rotate(new Vector3(0.0f, 0.0f, angleDiff));
angle = angleT;
}
}
I have to rotate my cannon type of object with 360 degrees.