- Home /
 
               Question by 
               galvasimo96 · Dec 06, 2021 at 02:16 PM · 
                rotationvector3quaternionpointmiddle  
              
 
              Rotation of object placed in the middle point between two points?
Hello everyone,
My situation is that I want to rotate an object by changing the position of two points. This points are at the ends of a segment which's middle point is my object.
This is the code and it's working around the z axis, but when I try the same on the y axis it doesn't work; I need the rotation on both z and y axis at the same time.
 Vector3 direction = p2.transform.position - p1.transform.position;
 object.transform.rotation = Quaternion.FromToRotation( new Vector2(object.transform.position.x, object.transform.position.y) , new Vector2(direction.x, direction.y) );
               Comment
              
 
               
               Quaternion rotation = Quaternion.LookRotation( direction , Vector3.up );
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                