How to get an AI to look at player without Navmesh ?

I’m currently using lookAt but it does not work because when the player passes the 270* angle the enemy rotates all the way in the opposite direction to face the player instead of just turning 1*.

All the tuts I’ve seen only show AI navigation and rotation on the Navmesh Agent, but I need to seperate the AIs movement and rotational destinations.
I’m still a rookie with Quaternions and Vectors, can someone please offer some insight to making an object look at something else without the weird problems mentioned above, thanks.

Can you use; Unity - Scripting API: Vector3.RotateTowards instead?

Hello,
I think i can recognize your problem.You can do the code instead of “lookat”.
Here is the code:
var target : Transform;
function Update ()
{
var relativePos = target.position - transform.position;

var rotation = Quaternion.LookRotation(relativePos);

transform.rotation = rotation;

}

looking forward to your reply.

Thanks


It did not work because the AI is rotating on all axis, and now is floating (even with rigidbody attatched).

I tried transform.rotation.y = rotation.y. But that did not work because like mentioned before it causes the object to stop tracking when the player moves into the 250* spot.

I need for th AI to only rotate on the Y axis towards the players general area, I’ve been experimenting for a while and not much is working, any advice is welcome

Edit :__ __NavMeshAgent.Move
I have temporarily found a fix for this problem but it is still not well suited for what I’m doing.

Example using a character controller - but the Vector functions could be used the same way without CharacterControllers

public float movementSpeed = 0.03f;
public Vector3 movementVelocity = Vector3.zero;
public float turnRate = 1.11f;

CharacterController cmp_cc;          

    void Start () 
    {
        cmp_cc = GetComponent<CharacterController>();
    }

   //move player one step (movement speed) toward a point
    public void moveToward( Vector3 targetPoint)
    {

        Quaternion rotation = Quaternion.LookRotation(targetPoint - transform.position);
        rotation.x = 0f; //don't change (x) up/down rotation
        rotation.z = 0f; //don't change (z) side rotation
        transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * turnRate);

        Vector3 movementVelocity = transform.forward * movementSpeed;

        movementVelocity.y = -.08f; //apply some gravity

        cmp_cc.Move ( movementVelocity );

    }

Solved, setting the rotation.x and rotation.z to 0 solved the problem I was having with the AI not rotating properly on an individual axis. I thought of trying that method before but I thought it wouldn’t work because it would be the same as setting: transform.rotation.y = rotation.y;
But it seems that weren’t the case - thanks for the help