Enemy object model not facing the player correctly

I created an enemy object which has a model and wrote a script that makes the enemy face the player when the player is close. However, when I get close the model of the enemy is rotating wrong, i.e. it should be rotated 90 degrees to make the model face the player correctly. Here is a pic of the problem:

You can see how the model is facing the player sideways (and its like that all the time when following the player, I tried to somehow add 90 degrees to the enemy object and make the model face the player correctly but I don’t know where to modify that or how. The code for rotation is this:

private void Update()
{
if (Vector3.Distance(igrac.position, this.transform.position) < 10)
{
Vector3 direction = (igrac.position - this.transform.position);
direction.y = 0;

        this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f);
    }

Heya :slight_smile:

There are a few ways of doing this. One is to add 90 degrees on the next frame. It might look something like this:

this.transform.rotation = Quaternion.Slerp (this.transform.rotation, Quaternion.LookRotation(direction), .1f);
this.transform.Rotate(0, 90, 0); //this value might be on the wrong axis, or maybe it needs to be negative instead.

Of course, this isn’t the most efficient way of solving the problem, but it’s probably the simplest to understand.

Another way of doing this might be something like this, although I haven’t tested it so it could be completely wrong.

this.transform.rtation = Quaternion.Slerp (this.transform.rotation + Quaternion.Euler(0, 90, 0), Quaternion.LookRotation(direction), 0.1f);

I hope I helped :slight_smile: