How should I use code to achieve the same function in unity3d?

How should I use code to achieve the same function in unity3d?

In Unity3d:

            Quaternion rotation = Quaternion.LookRotation(mainCamera.transform.TransformVector(Vector3.forward), mainCamera.transform.TransformVector(Vector3.up));
            this.target.rotation = rotation;

How should it be translated to PlayCanvas?

Try this:

var lookMat = new pc.Mat4();
var rotation = new pc.Quat();
lookMat.setLookAt(pc.Vec3.ZERO,mainCamera.forward,mainCamera.up);
rotation.setFromMat4(lookMat); 
this.entity.setRotation(rotation);
2 Likes

@FBplus
Perfect and correct! The problem has been solved!
Thank you very much, God!
感谢大神哈哈

1 Like