- Home /
How would you make a ray collide with a Gizmos sphere (float)
I need help with trying to make a ray cast hit a gizmos sphere(float) and tell me that they are colliding. I could use colliders but I'm trying to avoid that, because I want to keep those for physics not for scripted actions and I don't want two collider components on one object.
What is a "gizmos sphere(float)"? It is a very common scripted action to shoot a ray into the world and see what it hit.
Gizmos are used form seeing things in the editor. I could just use the collider but I'm trying to find a way to get it to interact with a field that I can set and I want the physics collider to only interact with physics objects and not the interacter.
Answer by NorthStar79 · Jan 18, 2018 at 05:43 AM
if you mean Gizmos.DrawSphere you can not detect it with ray (nor colliders), they are only for debugging and they can not interact with physics. also hey will not work at all once you build your game. again; gizmos are only for visual debugging for use in editor only,
I know that the can't detect the gizmo its self but I want to know how or if you can have the ray collide or inform me if it hit's the floats range.
I know your saying you understand you can't detect it, but your also saying can you have it collide :P
The easiest way to do this is to just create an actual sphere in it's place.
use gameobject.instantiate()
to create a sphere there ins$$anonymous$$d of a gizmo and add a sphere trigger collider. now you can do that.
you can not use rays for checking them if they hit the float range too. you can implement your own logic with c# for example, you can draw an imaginary line with Linear equation and check some points on that line if it equals your target. but that will be CPU intensive for your game if it is written with c#. on the other hand sphere colliders and rays are reasonably cheap processes.
Okay thanks, I was thinking about using a equation, but if its cpu intensive the I'll just use a collider.
Your answer