Hi, I found that Quaternion.LookRotation can look at the object position. But unforunately it can only look with z axis. Is there any way to make it look for the y axis ?
Note :
I’m working on ARToolkit project where they set the scene on their own. It’s so complicated to explain how it works but I can only show you that the transform is modified like this : Upload and share screenshots and images - print screen online | Snipboard.io . It forced me to use opposite y axis to look at the target.
So it sounds like if you used Quaternion.LookRoation you guy will face that information sign and you need him to face forward but still aligned exactly with the sign?
If so keep the code you have to make him line up and look at the sign then do this:
transform.Rotate(0,90,0);
This will then rotate him 90 degrees around the y-axis (change it to -90 if he ends up facing backwards)
It does not exactly work as LookRotation, but you could give a try to Quaternion.FromToRotation which gives you the rotation to align a vector to another one.
Actually it doesn’t have to do with the information sign.There are 2 objects in the scene. When it detected 2 markers, those objects should face to each other. The problem is ARToolkit set the transform like this. Because of that I must use opposite y axis to face the other object. This is the screenshot of my scene when I run it. Hope this helps you understand what I really up to.
So I tried using the Quaternion.FromToRotation but it still facing to z direction. This is what it looks like. Or maybe I’m using it wrong so it gives me the wrong facing direction ?
This is the script I used :
Vector3 targetDir = data.OtherMarker.transform.position - transform.position; // OtherMarker.transform.position = second marker ; transform.position = base marker
float step = 1 * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F);
Debug.DrawRay(transform.position, newDir, Color.red);
transform.rotation = Quaternion.FromToRotation(data.BaseMarker.transform.position, targetDir);
I see the problem. You models are being imported with their local Forward = World Down, local right = world Left, and local UP = world backward
You could try reimporting the models so they align with the world co-ordinates then all the Rotation API functions will work out of the box. You could also try this, since your model’s local UP is -Vector3.forward
I’m not sure but this might work:
Vector3 relativePos = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos,-Vector3.forward);