- Home /
Question by
RadZaeem · May 27, 2014 at 03:19 PM ·
raycastterrainslowcapsulecast
Game become slow after CapsuleCast on terrain?
I have a terrain object. when I CapsuleCast from camera to terrain the game slows down badly. However if I raycast other GameObjects it does not slows down? Does this have to do with terrain resolution or stuff?
int i = 0;
while (i < Input.touchCount) {
if (Input.GetTouch (i).phase == TouchPhase.Began) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch (i).position);
Vector3 p1 = ray.origin;
Vector3 p2 = ray.origin + (ray.direction * pickDistance);
if (Physics.CapsuleCast (p1, p2, pickRadius, ray.direction, out hit, pickDistance)) {
Debug.Log ("hit something");
}
}
}
++i;
Comment
Add some debug numbers to see how big this CapsuleCast is?
Answer by meat5000 · May 27, 2014 at 11:29 PM
What makes the Raycasting slow is the inclusion of the Hit information. To supply this info the function has a lot more work to do. Leaving out Hit from the arguments makes the raycast faster.
I'm guessing that raycasting the terrain results in a hit every time and as you have put it into a while loop which never ends the raycast is being pounded out with ferocity.