x


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

more ▼

asked Apr 22 '11 at 04:21 AM

Chris 35 gravatar image

Chris 35
86 14 14 21

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

1 answer: sort voted first

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.

more ▼

answered Apr 22 '11 at 04:35 AM

burgunfaust gravatar image

burgunfaust
260 5 7 17

could you show my error in relation to my code ?

Apr 22 '11 at 05:41 AM Chris 35

What are you trying to do with this script exactly?

Apr 22 '11 at 12:36 PM burgunfaust
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x5095
x3465
x1535
x181
x18

asked: Apr 22 '11 at 04:21 AM

Seen: 691 times

Last Updated: Apr 22 '11 at 04:21 AM