Thursday, 2 May 2013

Following AI code update

Hope we have fixed the ai circling bug with this snippet of code.
if we change this part of the previous code

//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

to:


//move towards the player if not too close

if ( ( myTransform.position - target.position ).sqrMagnitude > 4F )
{

myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

}
 
it should only move towards the player if the player is a certain distance away so it should in theory stop moving all together if it is so many units close to the player.

1 comment:

  1. I have put this code in, and so far so good. It is working : )

    ReplyDelete