raycast

Hi,

tried out a raycast but it seems to really hurt performance when an GO passes thru the raycast (it freezes momentarily then continues).

anyone else have experience of this?

thanks

I’m using raycast and it’s fine. Raycasts are somewhat expensive you want to be sure you’re only doing as many as really needed.

My app uses raycasts to see if your finger is over a ball. The one optimization I did was to put set the balls on their own layer and restrict the raycast to that layer. The floor the balls rest on is on another layer because I don’t care about touches on the floor.

how many polygons do your objects have?

just simple spheres at the moment

I know simple spheres that easily have 500-700 polygons which would be quite a bit critical given that this is 10%+ of your whole polygon budget onscreen

Thanks for the reply.

turns out it was not a Raycast issue but an instantiation one. The bullet prefab mesh was far to heavy so therefore caused the freeze/stutter. A more simplified bullet works fine.

void FixedUpdate () 
	{			
			rayDirection = transform.TransformDirection(Vector3.left);
			
			if(Physics.Raycast(transform.position,rayDirection,out rayHit,Mathf.Infinity,layerMask))
			{
				
				if(!hasFired)
				{	
					bulletClone = (GameObject) Instantiate(bullet,bullet.transform.position,bullet.transform.rotation);
					hasFired = true;
				}
		
			}
			else hasFired = false;
	
		}

thanks

Just to clarify, when you say “simple spheres”, you’re speaking of your colliders, not your model geometry, right? In which case, a simple sphere would be pretty cheap as opposed to a sphere-ish model with tons of polys.