It makes my game lag when I apply it to an object. All it’s supposed to do is follow my character without modifying the y position so it always stays on the ground. If it collides with my character then my character loses 1 hitpoint. Here’s a screen shot of the settings for the rigidbody and other components of the enemy that I applied this script to. http://i.imgur.com/yDpFhAG.png?1 The little crab like things are what the enemy looks like.
It looks like it I remove transform.LookAt(Player.transform.position); it stops lagging. Does anyone know why?
NEW FINDING Changing collision detection to discrete also makes the problem go away, even in the presence of transform.LookAt.
public float Speed;
void Start () {
Player = GameObject.FindWithTag("Player");
transform.LookAt(Player.transform.position);
}
void FixedUpdate()
{
SeekTarget();
}
void SeekTarget()
{
Vector3 MoveTowardsPosition = Vector3.MoveTowards(transform.position,Player.transform.position, Speed * Time.deltaTime);
MoveTowardsPosition.y = transform.position.y;
rigidbody.MovePosition(MoveTowardsPosition);
transform.LookAt(Player.transform.position);
}