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

AddForce by Touch speed problem (Solved)

$
0
0
Hello, this is my first question. I hope I am asking correctly. I have a game project that throws a ball with a touch screen. The speed of the ball depends on the time you touch the screen. And its direction depends on the direction of your touch. My problem is that the speed of the ball varies on different phones. For example, "huawei mate 10 light" shots slower on the phone, but "samsung S7" shots are extremely fast. To fix this problem, I limited the rate of fire. But it is not a sufficient solution. My main question: How can I stabilize the throw speed of the ball? Here is throwing part of my code: if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { StartTime = Time.fixedTime; startPos = Input.GetTouch(0).position; } if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) { EndTime = Time.fixedTime; TouchTime = EndTime - StartTime; endPos = Input.GetTouch(0).position; direction = endPos - startPos; Debug.Log("Süre : " + TouchTime); if (TouchTime < 0.08f) { return; } else { rb.isKinematic = false; Vector3 ThrowForce; ThrowForce.x = (direction.x * XYForce) * Time.deltaTime; ThrowForce.y = (direction.y * XYForce) * Time.deltaTime; ThrowForce.z = (ThrowForceZ / TouchTime) * Time.deltaTime; if(ThrowForce.z > 650) { ThrowForce.z = 650; } if (ThrowForce.y > 400) { ThrowForce.y = 400; } rb.AddForce(ThrowForce); rb.AddTorque(100, 0, 0); Destroy(rb.gameObject, 3f); thank you for your time. Huseyin KARAASLAN,

Viewing all articles
Browse latest Browse all 1264


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