I’m using the below script to do a papertoss kind of game. My directions and velocity are working well. But, when the object moves ( either free falls or under the influence of AddForce ), I can see a frame by frame motion of the object rather than a smooth flow.
Any idea what I’m doing wrong?
var projectile : GameObject;
var clone;
var distance: Transform;
var Prefabball : GameObject;
var elevationAngle : Vector3;
var throwForce : int;
var angle =“10”;
var force=10;
var shouldApply=false;
var touchStart: Vector3;
var touchEnd : Vector3;
var ball:GameObject;
var v:Vector3;
function Update () {
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase == TouchPhase.Began) {
touchStart = Input.GetTouch(i).position;
}
else if (Input.GetTouch(i).phase == TouchPhase.Ended) {
touchEnd=Input.GetTouch(i).position;
Launch();
}
}
}
function FixedUpdate() {
}
function Launch()
{
var p1:Vector3 = new Vector3();
var p2 :Vector3 = new Vector3();
touchStart.z = Camera.main.nearClipPlane+.1f; //push it a little passed the clip plane for camera, just to make sure its visible on screen
touchEnd.z = Camera.main.nearClipPlane+.1f;
p1 = Camera.main.ScreenToWorldPoint(touchStart);
p2 = Camera.main.ScreenToWorldPoint(touchEnd);
ball=GameObject.Find(“PaperBall”);
v = (p2-p1);
v.z=-1*Vector3.Distance(p2,p1);
ball.rigidbody.AddForce(v*1000,ForceMode.Impulse);
shouldApply=true;
}