Hello,
I’m trying to get 5 raycast systems to work but I’m having difficultly trying to offset them.
What I’m trying to do is to have a raycast come from my Input.mousePosition, but also have 4 other raycasts around that, that are slightly offset. But I suck when it comes to vectors.
So basically, this is how I want my set up:
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var layerMask = 1 << 14;
Physics.Raycast (ray, hit, 200, layerMask); // center line
Physics.Raycast (ray, hit.(z + 2) (x -2), 200, layerMask); // upper left
Physics.Raycast (ray, hit.(z + 2) (x +2), 200, layerMask); // upper right
Physics.Raycast (ray, hit.(z - 2) (x -2), 200, layerMask); // lower left
Physics.Raycast (ray, hit.(z - 2) (x +2), 200, layerMask); // lower right
This obversely isn’t going to work, but thats what I am trying to achieve. So each raycast that is being shot from the Input.mousePosition is to be offset by +2/-2. I also have a feeling that it has nothing to do with the ‘hit’, but is to do with the ray that I need to be adjusting?
I would appreciate any help with this.
------ UPDATE ------
Okay, so I’m making some progress. I have 5 raycasts that are shot with an offset from the camera, but towards the other end of the shot, they are angling towards each other. Here is a screen shot to help explain:
Here is my current code:
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var layerMask = 1 << 14;
var hitPoint : RaycastHit;
if(debugClick){//chooseLocation){
layerMask = ~layerMask;
// center line
Physics.Raycast (ray, hit, 200, layerMask);
Debug.DrawLine (ray.origin, hit.point);
// line 1
var offset = Vector3(ray.origin.x + 2, ray.origin.y, ray.origin.z);
var direction = transform.position;
Physics.Raycast (offset, direction, hit, 200);
Debug.DrawLine (offset, hit.point, Color.green);
// line 2
var offset2 = Vector3(ray.origin.x - 2, ray.origin.y, ray.origin.z);
var direction2 = transform.position;
Physics.Raycast (offset2, direction2, hit, 200);
Debug.DrawLine (offset2, hit.point, Color.red);
// line 3
var offset3 = Vector3(ray.origin.x, ray.origin.y, ray.origin.z + 2);
var direction3 = transform.position;
Physics.Raycast (offset3, direction3, hit, 200);
Debug.DrawLine (offset3, hit.point, Color.blue);
// line 4
var offset4 = Vector3(ray.origin.x, ray.origin.y, ray.origin.z - 2);
var direction4 = transform.position;
Physics.Raycast (offset4, direction4, hit, 200);
Debug.DrawLine (offset4, hit.point, Color.yellow);123
123