rotate Y axis towards position
I have an object that rotates to match the collider's normals. I don't want the collider's normal to determine what the Y axis rotation should be. Instead, I want the Y axis to rotateTo to desired position in space.
Vector3 lookAtPos = new Vector3(1,2,3);
RaycastHit hit;
Ray ray = new Ray(transform.position + (transform.up*0.75f), -transform.up);
Collider col = GameObject.Find("wall").GetComponent<Collider>();
if (col.Raycast(ray, out hit, 1f)) {
transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
}
The idea is to have the object walk on walls while looking at moving object with the Y axis. Any ideas of how to finish this code?
Not too sure what you're asking, but maybe something like this could help.
transform.up = (object.transform.position - transform.position).normalized;
It's like transform.LookAt although it rotates towards the object with a differnet angle.
that doesn't really work. it's explained more here
http://answers.unity3d.com/answers/138350/view.html
As I said .. use LookAt
and be sure to use the WorldUp
argument
Answer by Fattie · Dec 18, 2015 at 01:59 PM
is it possible LookAt
could help you here? Note the WorldUp argument option.
Holy gigabytes!! transform.LookAt(lookAtPos, transform.up)
worked!!
Lol good one. Note that you got the "ALEX TREBE$$anonymous$$ AWARD" for closing-out questions. Don't hesitate to post your further questions.
Your answer
![](https://koobas.hobune.stream/wayback/20220612053110im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why does RotateTowards rotate in an "orbit" rather than on the spot? Help me understand! 0 Answers
How to use LookAt for only one axis? 1 Answer
How to face towards vertical collider? 0 Answers
Best Method to Rotate Camera around a GameObject while looking at another? 0 Answers
Rotate Towards Mouse in 3D 0 Answers