Skip to content

Instantly share code, notes, and snippets.

@flashfoxter
Forked from tracend/AvoidObject.js
Last active August 29, 2015 14:10
Show Gist options
  • Save flashfoxter/db7b25697867a896d687 to your computer and use it in GitHub Desktop.
Save flashfoxter/db7b25697867a896d687 to your computer and use it in GitHub Desktop.
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