Created
March 30, 2011 00:18
-
-
Save tracend/893631 to your computer and use it in GitHub Desktop.
Unity3D: Follow and object - 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 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