Raycasting error?

Basically I have an object which sends 2 raycasts out downwards to detect if anything is hit, I’m using this code:

if (Physics.Raycast (Vector3(transform.position.x + 0.3, transform.position.y, transform.position.z), -Vector3.forward, hit, ydist, layerMask) || Physics.Raycast (Vector3(transform.position.x - 0.3, transform.position.y, transform.position.z), -Vector3.forward, hit, ydist, layerMask)) {
}

They’re hitting objects but not in the correct direction, it’s odd because I also have rays firing out upwards, left and right and they all seem to be working correctly. The image below shows what I mean, the object with the x on it is the object which the script is contained on and the red line denotes the direction that the raycast should be fired (using Debug.Draw). The box which is outlined in red is the box which is hit which clearly isn’t right.

alt text

Any help or ideas would be GREATLY appreciated.

Edit Note : Even if I reduce both of the “0.3’s” to 0 it still doesn’t work so thats not the problem :frowning:

It’s because you are firing towards vector(0,-1,0) from your position, making skewed lines instead of straigh lines from your position. something like this(C#)…

Vector3 pos1 = transform.position;
pos1.x += 0.3;
Vector3 dir1 = pos1 - Vector3.forward;

Vector3 pos2 = transform.position;
pos2.x -= 0.3;
Vector3 dir2 = pos2 - Vector3.forward;

if (Physics.Raycast (pos1 , dir1 , hit, ydist, layerMask) || 
    Physics.Raycast (pos2 , dir2 , hit, ydist, layerMask)) {
}