- Home /
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;
}
Comment
Best Answer
Answer by whydoidoit · Jul 31, 2012 at 05:06 PM
You need to multiply a Quaternion by transform.forward like this:
Quaternion.AngleAxis(20, transform.up) * transform.forward
"Quaternion.AngleAxis(20, transform.up) * transform.forward"
The most simple and rewarding answer I have received on the forums. You are a champion.