- Home /
How to make object turn around and go back to original place?
Alright guys, so I have made it so that my model goes from point A to point B and back, but I was wondering if it was possible to make it turn around instead of going in reverse back to its original spot? I know I should add some quaternion thing in there but not sure where or what...
Here's what I have so far:
var pointB : Vector3;
var speed = 20.0;
var rotateSpeed = 3.0;
function Start () {
var pointA = transform.position;
while (true) {
yield MoveObject(transform, pointA, pointB, 20.0);
yield MoveObject(transform, pointB, pointA, 20.0);
}
}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {
var i = 0.0;
var rate = 100.0/time;
while (i < 1.0) {
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield;
}
}
Thanks!!
Is there a reason why you need to script this movement ins$$anonymous$$d of using an animation clip?
You should use an animation clip, this is a lot more better.
Animation doesn't have to be the answer... scripting movement is fine too
Answer by perchik · Jul 17, 2013 at 05:52 PM
Between moving the object one direction and the second direction, just Slerp the rotation from(0,0,0) to (0,180,0) or whatever it needs to turn around. You can write another function (ie Rotate Object) that just turns it by 180 degrees over some period of time
could you possibly show me an example of this?? sorry i'm a noob! thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613110307im_/https://answers.unity.com/themes/thub/images/avi.jpg)