Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Rotate when the objekt reaches a Point

$
0
0
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.

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>