- var target : Transform; //the target
- var moveSpeed = 3;
- var rotationSpeed = 3; //speed of turning
-
- var myTransform : Transform; //current transform data of A.I.
-
- function Awake()
- {
- myTransform = transform;
- }
-
- function Start()
- {
- target = GameObject.FindWithTag("Player").transform; //target the player
-
- }
-
- function Update () {
- //rotate to look at the player
- myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
- Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
-
- //move towards the player
- myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
-
-
- }
from what I can gather so long as we have the firstperson camera tagged player
(which i think it is) we attach this code to the A.I. and it should follow
no matter how far away the player is.
Also this was on UnifyCommunity wiki.
.http://wiki.unity3d.com/index.php/Flocking
Tuesday, 16 April 2013
Possible Following A.I. code?
I found this on UnityAnswers, its originally for an enemy to follow player but it doesn't have any triggers in it its simply the following aspect of the script. It's Java.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment