x


Raycast LayerMask

Alright, back again trying to get layermasks on my raycast to work. My code:

var range : float = 10f;

//var accuracy : float = .1f;

function Update () {

//sets perfect target

//var target = (transform.TransformDirection (Vector3.forward));
//target.rotation = transform.rotation;
// adds in realistic inaccuracy based on input
//target = (target.x + targetxaccuracy, target.y + targetyaccuracy, target.z)



var mask : int = 9;

var maskl : int = 1 << mask;




var hit = (Physics.Raycast (transform.position, transform.forward, range, maskl));
Debug.DrawLine (transform.position, transform.forward, Color.red);
if (hit != null) {
print("Companion Cube in sight!");
}

else 
    {
    print("Nothing there");
    }
}

This is attached to my camera (Sorry for the extra bits, I was programming for more functionality. There is One companion cube in my world with the layer mask test on layer 9.

I have 2 MAJOR problems.

1st: the ray-cast is using 0,0,1 as its target point. Not following the direction. Note: I've tried using transform.TransformDirection (Vector3.forward) and it came up with the same result. It appears to not be taking a direction as using it as a solid point in space. The debug line draws heading in that direction like a compass.

2nd: the debug is spitting back that the ray-cast is in fact touching my companion cube. Which I know is crap, because I've deleted it from the world, and still retained my positive message.

Anyone understand this voodoo?

more ▼

asked Oct 13 '11 at 10:27 PM

sgmongo gravatar image

sgmongo
155 11 17 21

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1536
x42

asked: Oct 13 '11 at 10:27 PM

Seen: 1174 times

Last Updated: Oct 13 '11 at 10:27 PM