- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
erfan · Jul 04, 2013 at 04:30 PM ·
rotationtranslationsmoothlysending object
How to Rotate and Translate smoothly an Object between 2 point?
hi . i have this code for above problem. an object that want follow thw way points. #pragma strict
var waypoint:Transform [];
internal var currentWay : int=0;
var TransformSpeed:float;
internal var startTime:float;
var duration:float;
var time:float;
function Start () {
startTime=Time.time;
}
function Update () {
//transform.Translate(0,TransformSpeed*Time.smoothDeltaTime,0);
if (this.transform.rotation.z-waypoint[currentWay].transform.rotation.z<0.5 &&
Vector3.Distance(this.transform.position,waypoint[currentWay].transform.position)<0.5)
{currentWay++;
startTime=Time.time;}
var target:Transform =waypoint[currentWay];
transform.rotation=Quaternion.Slerp(
this.transform.rotation,target.rotation,(Time.time-startTime)/duration);
transform.position=Vector3.Lerp(
transform.position,target.position,
(Time.time-startTime)/duration);
}
but the problem is each time object reach to the Way point it stops and then moves again. and it is not smoothly. how can i fix it.
Comment
Read the scripting reference, it's all in there, with examples
1 - this looks like its JS right? 2 - you want an object to just move between two points back and forth smoothly without stopping?
Your answer
![](https://koobas.hobune.stream/wayback/20220613105502im_/https://answers.unity.com/themes/thub/images/avi.jpg)