Hi,
i would like my character to anticipate the direction of the enemy, in order to catch him. But my character looks too slow, and rotate just after the enemy passes him. So i would like the character to anticipate the next step of the enemy, with Vector.forward * 5 (in this example), but he does not seem to understand what i am trying to do, the z axis does not rotate fast enough so that the character can catch the enemy. Would you know why?
Here is the code :
//rotate the character every frame
if(enemyFound == true){
//enemy to follow
var newTransform : Vector3 = enemyToFollow.transform.position;
newTransform += newTransform.forward*5*Time.deltaTime; //anticipate a bit, does not work
directionToClosestEnemy = newTransform - transform.position;
tempRot = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(directionToClosestEnemy),2*Time.deltaTime);
}
//make him move
if(enemyFound == true){
targetVelocity = enemyToFollow.transform.position - transform.position;
targetVelocity = targetVelocity.normalized; // Is now speed 1, going correct way
targetVelocity = targetVelocity * MOVE_SPEED;
var velocityChange = (targetVelocity - velocity);
velocityChange.y = 0;
rigidbody.AddForce(velocityChange, ForceMode.Force);
}
Thanks
Edit: do you mean like this ?
var newTransform : Vector3 = enemyToFollow.transform.position;
newTransform += enemyToFollow.transform.forward * 100 * Time.deltaTime;
directionToClosestEnemy = newTransform - transform.position;
tempRot = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(directionToClosestEnemy),2*Time.deltaTime);