x


RayCast offset rotation 20 degrees

Hi,

How would I rotate a RayCast 20 degrees off the axis of the gameObject?

Thanks.

// Check to see if there is anything between the Terrorist and the Player 
if (Physics.Raycast(transform.position + Vector3(0, 1, 0), transform.forward, hit)){ // Vector3 lifts the Ray off the floor 1mt
 Debug.DrawLine (transform.position + Vector3(0, 1, 0), hit.point, Color.red);
 print(hit.collider.gameObject.name);

if(hit.collider.gameObject.tag == "Player"){
 globalVars.GetComponent(GlobalVars).playerBeingHit = true;
}
 else globalVars.GetComponent(GlobalVars).playerBeingHit = false;
 } 
more ▼

asked Jul 31 '12 at 04:50 PM

Griffo gravatar image

Griffo
1.7k 20 48 67

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

1 answer: sort voted first

You need to multiply a Quaternion by transform.forward like this:

   Quaternion.AngleAxis(20, transform.up) * transform.forward
more ▼

answered Jul 31 '12 at 05:06 PM

whydoidoit gravatar image

whydoidoit
33k 11 23 100

Thank you ..

Jul 31 '12 at 06:28 PM Griffo
(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:

x2163
x1528
x109

asked: Jul 31 '12 at 04:50 PM

Seen: 426 times

Last Updated: Jul 31 '12 at 06:29 PM