I am making a skeet shooter game.
I have a working code that uses raycast to shot at the middle of the screen and blow up a object if it hits it.
Problem is that its so hard to hit because the ray is so tiny. I am looking for a way to be able to decide how big my hit area should be.
Can anyone point me in the right direction? Maybe raycast is not the way to do this.
Code this far:
function Update () {
if(Input.GetButtonDown("Fire1"))
{
//var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var ray = Camera.main.ScreenPointToRay (Vector3(Screen.width/2,Screen.height/2,0));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 1000)) {
Debug.DrawLine (ray.origin, hit.point);
var objectHit : GameObject = hit.collider.gameObject;
objectHit.SendMessage ("GetHit", SendMessageOptions.DontRequireReceiver);
}
}
}
I have been thinking of shooting more rays in a pattern.
Shooting a ticker ray if possible.
Shooting a invisible object with a Sphere collider set to is trigger.
Any of this seems plausible or do you know of a bether method I can look up how to do.
For one object closer than another, a wide sphereCast directly "on" the far one may still sometimes clip the near one. A loop with increasingly thicker sphereCasts works surprisingly well (even on a tablet.)
– Owen-ReynoldsI will set up a rig testing a raycast I know will miss and then a SphereCast that should hit the object if the sphere travels the line. Maybe with increasing size to see how it react to my scene. Then also understand bether how Sphere cast works, thanks :)
– Dutti