I’m working on a sort of RTS where you’ll be able to select object (character) and click around to move it.
To do this I’m casting a Ray from mouse if the hit object have the interactive class, I’ll consider it selected.
Now the problem is 'cause I need to add second collider which is pretty whide 'cause is used for attack range.
Obviously the ray hit this collider ignoring all other units inside of his radius… and I’m stuck :\
That’s why I need to ignore the shperecollider but not the box collider… advice?
Well, one way would be to utilize the physics layers, found in Edit->Project Settings->Physics. You can customize which objects collide with others, and specify a layer on your raycast.
The other option, which I’d highly recommend, would be to use a simple script that stores the attack radius as a float, rather than as a sphere bounding volume, and do that math manually, since the sphere isn’t a real collider.
don’t use physics for selecting more than one unit.
Back in my old wild days I used Physics.OverlapSphere() to select units by dragging GUI.Box()es over them.
It was incredibly slow.
A better way is using a List of selectable Entities und check if their position in screenSpace (Camera.main.WorldToScreenPoint(obj.transform.position)) is in my selection-rect.