- Home /
Raycast with tags problem, resultless raycast..
hi, i need some help here. i have a part of code to search unblocked neighbour with raycast. i need to get raycast that just collide with "WP" tag. both of the iteration shown a right results, so do the dump and the raycast, the raycast does success to collide something, but when i check what the raycast collided with, there is no result shown.... anyone knows whats wrong with this code..??
int flag = 0, flahNeigh = 0;
for(flag = 0; flag< wayPoints.WPList.Length; flag++) // iteration to seek neighbour nodes
{
for (flagNeigh = 0; flagNeigh < wayPoints.WPList.Length; flagNeigh++)
{
if (wayPoints.WPList[flag].loc != wayPoints.WPList[flagNeigh].loc) // dump its own node location
{
if (Physics.Raycast(wayPoints.WPList[flag].loc.position, wayPoints.WPList[flagNeigh].loc.position, out hitted)) // raycasting to each node else its self
{
if (hitted.collider.gameObject.CompareTag("WP")) // check if the ray only collide the node
{
print(flag + " : " + flagNeigh + " : " + wayPoints.WPList[flagNeigh].loc.position); // debugging to see whether the code works or not (the error comes)
}
}
}
}
}
thanks for the appreciation and answers... sorry if i have a bad english...^^
Answer by Owen-Reynolds · Dec 03, 2012 at 05:48 AM
For the form you're using, the second input of a raycast is a direction. If you want to shoot from flag to flagNeigh, that 2nd input should be `flagNeigh-flag` (I'm leaving off a lot, really subtract the position.)
The way you have it, flagNeigh is interpreted as a bad direction. Suppose it's (100,100). That counts as North-East.
The other form, where you give a ray, is the same. You don't build a ray from two points. You use a point and a direction.
flag and flagneigh is not the direction, it's counters for accessing the array of location actually... thx
Yes, they are indexes, that why I wrote "really subtract the position."
Look up raycast examples again. To shoot a ray down, input#2 is `-Vector3.up`, which is a direction -- not a point below the player.
Your answer
![](https://koobas.hobune.stream/wayback/20220613084837im_/https://answers.unity.com/themes/thub/images/avi.jpg)