where i swipe or flick sphere…but after flicking sphere while coming its down i want it to slow its speed…(like baloon) i want to hv baloon physics…plz help guys…
A real balloon has low mass and high drag. Adjust your parameters to reflect this.
thnx alot…
currently in my swipe or flick code does not detect the sphere or baloon object…my gameobjects flicks even if i swipe or flicks to screen …so now i want to detect sphere or baloon object and if i swipe on it then only it should travel upward…here is code… plz help guys…
using UnityEngine;
using System.Collections;
public class TouchMonitor : MonoBehaviour {
//var theprefab:GameObject;
public Rigidbody ball;
private Vector3 touchStart;
private Vector3 touchEnd;
private GameObject lineRenderer;
void Update () {
if (Input.touchCount > 0)
{
Touch t = Input.touches[0];
if (t.phase == TouchPhase.Began)
{
touchStart = t.position;
}
if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled)
{
touchEnd = t.position;
DoInput();
}
}
if (Input.GetButtonDown("Fire1"))
{
touchStart = Input.mousePosition;
}
if (Input.GetButtonUp("Fire1"))
{
touchEnd = Input.mousePosition;
DoInput();
}
}
//Start
//end
void DoInput()
{
Vector3 p1 = new Vector3();
Vector3 p2 = 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);
CreateLine(p1,p2);
Vector3 v = p2-p1;
ball.AddForce(v*10, ForceMode.Impulse);
}
//creates an purple line from pos1 to pos2 in worldspace
void CreateLine(Vector3 p1, Vector3 p2)
{
Destroy(lineRenderer);
lineRenderer = new GameObject();
lineRenderer.name = "LineRenderer";
LineRenderer lr = (LineRenderer)lineRenderer.AddComponent(typeof(LineRenderer));
lr.SetVertexCount(2);
lr.SetWidth(0.001f, 0.001f);
lr.SetPosition(0, p1);
lr.SetPosition(1, p2);
}
}