Why does using .Lookat() cause the enemy to look left instead of at player, and how can I fix it?

I am new to Unity. I have searched but I couldn't find any answers on this. Here is my code:

somethingPosition = new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z);
transform.LookAt(somethingPosition);


The somethingPosition only allows rotation of the Y axis so. Anyways, I have this script on the enemy AI.

The issue is this: the enemy looks at the player but looks to the left of the player. The same issue occurs when I have my follow code happen:

transform.position = Vector3.MoveTowards(transform.position, player.position, speed * Time.deltaTime);


The enemy will continue going to the left of the player but will not hit the player. What are some suggestions you guys can survive? Thanks!

I am aswell using a NavMesh and NavMeshAgent

Double check that your model of the character does not have an offset. If it does, the object's centre would be away from the model, which would cause all calculations (including LookAt) to point to that place. If you are using NavMeshAgents, there's a chance you are doing collisions based on the mesh, creating a bounding box around it, which would explain why everything else seems to be working.

• My character does not have an offset and I am using a NavMeshAgent too – Captain Caboose Jan 9 '19 at 16:43
• @CaptainCaboose Try creating a new cube, and add is as a direct child to player, reset all of its transformation so it has position (0, 0, 0). Make the cube small, so it represents a point. This is the center of your player. Now try to run the game again, and check where the enemy is looking at. Depending on the result, I may be able to add more details to my answer. It may be helpful if you add screenshots in your original question. – TomTsagk Jan 9 '19 at 16:48

Firstly, you have set target y value to look at to be transform.position.y. This can be okay or not depending on if you are getting the AI to look straight forward.

Secondly, different 3d modeling softwares have either a z-up or a y-up configuration. Check axis of player and AI.

Thirdly, for good results take an empty axes and child it to your player at position where you want your AI to lookat.

Also, as TomTsagk pointed out, your player origin might not be within its mesh and check colliders.

good Luck.