How to rotate a game object and stay?

There is an opponent gameobject.

It’s Rotation in Scene is -0, 270, 0

It can move towards the Character.

C -----------<---- move towards left hand side ------ O

If C is in left hand side of O, O will move to left hand side

I read

and

I added a code

function Update () 
{	    
        transform.rotation.x = -0;
        transform.rotation.y = 270;
        transform.rotation.z = 0;
        transform.Translate(movement.direction * movement.walkSpeed * Time.deltaTime);
}

Then, O rotates to face camera and moves backward.

What do I want to do is when C is on the right hand side of O, O can rotate to face C and move to the right hand side.

O ----> rotate and move to right hand side -------> C

        transform.rotation.x = 0;
        transform.rotation.y = 90;
        transform.rotation.z = 0;
        transform.Translate(movement.direction * -movement.walkSpeed * Time.deltaTime);

transform.LookAt(targetTransform); cannot be used because:

if C jump over O, O will falls down.

Or, how to limit transform.LookAt x,y,z?

did not mention it

There is a Quaternion.LookRotation function that works a bit like transform.LookAt, but looks along a vector rather than at a point. Get the direction from the opponent to the player, then set its Y component to zero (ie, you are getting the direction in the ground plane). Then, use this as the target direction for Quaternion.LookRotation:-

var heading = player.transform.position - transform.position;
heading.y = 0;
transform.rotation = Quaternion.LookRotation(heading);