Move object along the camera view over surface?

Good day community!

I would like to know how to make the player face the direction the camera is pointing at, but only considering it’s Y Axis, using an orbiting camera that rotates arround the player while he walk a surface, this is what I got so far:

Quaternion q = Quaternion.LookRotation(Camera.main.transform.forward, Camera.main.transform.up);
transform.rotation = Quaternion.Slerp(transform.rotation, q, Time.deltaTime * speed);
//transform.Translate(transform.forward * Time.deltaTime * (speed / 3f), Space.Self);

The problem with this code is that the object faces orientation where ever the camera points, and that is not correct, it should only rotate along it’s Y local axis. But I need some help by making it work, any help is highly apreciated.

Well, I think if you look at the example in scripting it’s:

public class ExampleClass : MonoBehaviour {
   public Transform target;
   void Update() {
       Vector3 relativePos = target.position - transform.position;
       Quaternion rotation = Quaternion.LookRotation(relativePos);
       transform.rotation = rotation;
   }
}

So, instead of using camera position, you use a point that has the cameras x, and z, but the player’s y.

The problem with this willmake the player “lay” over the surface instead of “stading”,because it takes “forward” as the first param.

I doubt they would have given that for an example if it did that.

It might be, I haven’t tried it, but I kind of doubt it. If you notice it takes one parameter, so it’s probably overloaded.

There is also a Lookat function which takes a vector 3, probably easier: