- Home /
Question by
imran_iot · Dec 16, 2016 at 08:38 AM ·
rigidbodyaddforcetouch controls
how do i move a object with direction of touch
hi , i am very beginner of game developing. i am developing a game where i have a ball and i want to move it by touch just like a soccer game where ball can move by the direction of touch but its move only forward direction and here is my code. plz help me. thank you
public float ThroughSpped;
public float ArchSpped;
void OnMouseDown() {
distance = Vector3.Distance (transform.position, Camera.main.transform.position);
Dragging = true;
}
public void OnMouseUp()
{
//Instantiate(this) ;
this.GetComponent<Rigidbody> ().useGravity = true;
this.GetComponent<Rigidbody> ().velocity += this.transform.forward*ThroughSpped;
this.GetComponent<Rigidbody> ().velocity += this.transform.up*ArchSpped;
Dragging = false;
}
void DraggingBall()
{
if (Dragging)
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Vector3 raypoint = ray.GetPoint (distance);
transform.position = Vector3.Lerp (this.transform.position, raypoint, Speed * Time.deltaTime);
Destroy(BallPrefabClone, 1f);
}
}
Comment