Created
March 30, 2011 00:20
-
-
Save tracend/893632 to your computer and use it in GitHub Desktop.
Unity3D: Raycast object avoidance - Source: http://wiki.dreamsteep.com/Unity_ai
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var target : Transform; | |
function Update(){ | |
//the direction vector to target | |
var dir = (target.position - transform.position).normalized; | |
var hit :RaycastHit; | |
if (Physics.Raycast(transform.position,transform.forward,hit ,20)){ | |
//no self collision | |
if(hit.transform !=transform) | |
{ | |
dir += hit.normal *20; | |
} | |
} | |
var rot = Quaternion.LookRotation(dir); | |
transform.rotation = Quaternion.Slerp(transform.rotation,rot,Time.deltaTime); | |
transform.position += transform.forward *20 *Time.deltaTime; | |
print (transform.rotation); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment