- Home /
Raycasting problems
how come the Normalize() function wont work for more then one variable ? i cant see any error in my code.....
var Bullet1_direction = Vector3(15,0,45); var Bullet2_direction = Vector3(0 ,0,1); var Bullet3_direction = Vector3(1 ,0,0); var length = 4;
function Update () { var Bullet1_diagonal = transform.TransformDirection(Bullet1_direction); Bullet1_diagonal.Normalize();
var Bullet2_diagonal = transform.TransformDirection(Bullet2_direction); Bullet2_diagonal.Normalize();
var Bullet3_diagonal = transform.TransformDirection(Bullet3_direction); Bullet3_diagonal.Normalize();
Debug.DrawRay(transform.position, Bullet1_diagonal length,Color.green); Debug.DrawRay(transform.position, Bullet2_diagonal length,Color.red); Debug.DrawRay(transform.position, Bullet3_diagonal * length,Color.blue);
if (Physics.Raycast(transform.position, Bullet1_diagonal,length)) { Debug.Log ("Bullet 1 hit green!"); } if (Physics.Raycast(transform.position, Bullet2_diagonal,length)) { Debug.Log ("Bullet 2 hit red!"); } if (Physics.Raycast(transform.position, Bullet3_diagonal,length)) { Debug.Log ("Bullet 3 hit blue!"); }
}
any help would be great
Answer by burgunfaust · Apr 22, 2011 at 04:35 AM
From the script reference:
If this vector is too small to be normalized it will be set to zero.
Normalize proportionally changes the vector to a 0 to 1 range, so
var Bullet1_direction = Vector3(15,0,45);
becomes (0.3,0.0,0.9)
var Bullet2_direction = Vector3(0 ,0,1);
becomes (0,0,1)
var Bullet3_direction = Vector3(1 ,0,0);
Becomes (1,0,0)
No change to the last two vectors, because they are already within the range in question.
Your answer
Follow this Question
Related Questions
Raycast help..... 2 Answers
Turret that shots a raycast to detect my character then shots at him. 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
ray cast not working ? 2 Answers