# Raycast help.....

 0 Hi, I was wondering how or if you can cast a diagonal ray in unity. see in my game one of the players weapons is a shotgun and i wanted to cast 3 rays from the player eg. one going straight forward and one on either side going around 45 degrees. is this possible ? how would i do it ? could i cast a ray from point A to point B with both Point A and B having a (x,y,z) location? code would be great thanks :) more ▼ asked Apr 20 '11 at 02:21 PM Chris 35 86 ● 14 ● 14 ● 21 Aldwoni 865 ● 27 ● 30 ● 34 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

2 answers: sort oldest
 0 Read up on the documentation on raycasting.. more ▼ answered Apr 20 '11 at 02:30 PM Joshua 6.4k ● 19 ● 25 ● 71 :) thanks heaps Apr 21 '11 at 12:39 AM Chris 35 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 i was wondering why this code doesn't work ? i want to just cast a ray and what ever it hits returns a print statement is my Debug.Draw ray correct ? ``````var xDirection = 15; `````` var yDirection = 0; var zDirection = 45; var length = 0.1; var hit : RaycastHit; function Update () { var diagonal = transform.TransformDirection (Vector3(xDirection,yDirection,zDirection)); Debug.DrawRay(transform.position, diagonal * length,Color.green); ``````if (Physics.Raycast (transform.position, diagonal,hit,length)) { print ("There is something in front of the object!"); } `````` } help please thanks more ▼ answered Apr 21 '11 at 01:00 AM Chris 35 86 ● 14 ● 14 ● 21 The "diagonal = transform.TransforumDirection" makes no sence to me. Just say "diagonal = Vector3(xDirection,....)" I think. Apr 21 '11 at 01:45 AM Joshua the transform.TransformDirection means that the ray will rotate with my character, because my player faces the direction of the mouse it needs that code so the ray follows. i still cant get it to detect the collision of the ray and an object tho Apr 21 '11 at 02:06 AM Chris 35 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

### Follow this question

By Email:

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

Topics:

x5092
x3464
x1535
x181
x16

asked: Apr 20 '11 at 02:21 PM

Seen: 1374 times

Last Updated: May 06 '11 at 11:21 AM