# Turning a gameobject around 180 degress

 0 function Update() { ``````if (!moving && !park) { if (!turnAround) { ///move staight on if no arrays transform.Translate(Vector3.forward * Time.deltaTime* speed); } else { var targetRotation = Quaternion.Euler(Vector3.Reflect(transform.position, Vector3.forward)); transform.rotation = Quaternion.Slerp( transform.rotation, targetRotation, Time.deltaTime * turnSpeed ); if (transform.rotation.y == -1) { turnAround = false; } } } `````` } Here is my code i am having problems turning the transform around a 180 degress then making turnAround = false to stop the rotate. It will be like when you hit a ball onto a wall at different angles the truck will turn then follow the forward motion the same. Thanks more ▼ asked Jul 17 '10 at 12:53 PM mark 1 37 ● 6 ● 6 ● 8 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 thanks i sorted it by doing ``````function RotateObject (thisTransform : Transform, degrees : Vector3, seconds : float) { if (rotating) return; rotating = true; var startRotation = thisTransform.rotation; var endRotation = thisTransform.rotation * Quaternion.Euler(degrees); var t = 0.0; var rate = 1.0/seconds; while (t < 1.0) { t += Time.deltaTime * rate; thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, t); yield; } rotating = false; } `````` more ▼ answered Jul 17 '10 at 01:35 PM mark 1 37 ● 6 ● 6 ● 8 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email: