Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

how do i move a object with direction of touch

$
0
0
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 ().useGravity = true; this.GetComponent ().velocity += this.transform.forward*ThroughSpped; this.GetComponent ().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); } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>