Skip to content

Instantly share code, notes, and snippets.

@tracend
Created March 30, 2011 00:18
Show Gist options
  • Save tracend/893631 to your computer and use it in GitHub Desktop.
Save tracend/893631 to your computer and use it in GitHub Desktop.
Unity3D: Follow and object - Source: http://wiki.dreamsteep.com/Unity_ai
var waypoint: Transform;
var speed: float = 15;
function Update () {
var target:Vector3 = waypoint.position;
var moveDirection: Vector3 = target -transform.position;
var velocity = rigidbody.velocity;
if (moveDirection.magnitude <1)
{
velocity = Vector3.zero;
}else{
velocity = moveDirection.normalized*speed;
}
rigidbody.velocity = velocity;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment