- Home /
 
               Question by 
               unity_04leanderweckner · May 10, 2020 at 04:09 PM · 
                rotationmovementplayerenemydestination  
              
 
              Rotate when the objekt reaches a Point
Hey! I just started Programming with C#. The script makes an Objekt go from PointA to PointB and back. I just wanted that the Objekt rotates 180 degrees whenever the Objekt reaches pointA or PointB. This is what i tried:
{ public Vector3 pointB; public float turnspeed;
 IEnumerator Start()
 {
     var pointA = transform.position;
     while (true)
     {
         yield return StartCoroutine(MoveObject(transform, pointA, pointB, 100.0f));
         yield return StartCoroutine(MoveObject(transform, pointB, pointA, 100.0f));
         
         if(transform.position == pointB)
         {
             transform.Rotate(new Vector3(0f, 180f, 0f));
         }
         if(transform.position == pointA)
         {
             transform.Rotate(new Vector3(0f, -180f, 0f));
         }
     }
 }
 IEnumerator MoveObject(Transform thisTransform, Vector3 startPos, Vector3 endPos, float time)
 {
     var i = 0.0f;
     var rate = 1.0f / time;
     while (i < 1.0f)
     {
         i += Time.deltaTime * rate;
         thisTransform.position = Vector3.Lerp(startPos, endPos, i);
         yield return null;
     }
 }
}
The objekt does not Rotate 180 degrees on the Y axis. Can someone help me. I am dumb.
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Curve player movement 1 Answer
make player move in direction it's facing 2 Answers
Mouse Orbit Script with mecanim & turning character 0 Answers
can anyone find the issue with this code? 2 Answers
Unity Enemy Range detection 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                