- Home /
Question by
daviddickball · Jun 06, 2015 at 05:13 PM ·
movementtranslatewaypoints
Object moving between waypoints is jerky
Hi, I'm moving an object between 3 waypoints, but the movement is jerky. Is there a better way to do achive this? My code is below:
#pragma strict
public var target1 : GameObject;
public var target2 : GameObject;
public var target3 : GameObject;
public var moveSpeed = 5.0;
public var rotateSpeed = 6.0;
public var distanceToTarget : float;
public var currentTargetNum : int = 1;
private var currentTarget : GameObject;
function Start () {
currentTarget = target1;
}
function Update () {
distanceToTarget = Vector3.Distance(currentTarget.transform.position, transform.position);
if(distanceToTarget > 2)
{
//--move and rotate towards target
var rotation = Quaternion.LookRotation(currentTarget.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotateSpeed);
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}else {
//--switch to next target
currentTargetNum++;
if(currentTargetNum>3){
currentTargetNum = 1;
}
if(currentTargetNum == 1){
currentTarget = target1;
}else if(currentTargetNum == 2){
currentTarget = target2;
}else if (currentTargetNum == 3){
currentTarget = target3;
}
}
}
I also want at a certain point to disable this movement and allow the object to drift for about a second to a gradual stop, but right now it stops dead. Shoudl I be using some physics to move it like AddForce instead of Translate?
Comment
Your answer

Follow this Question
Related Questions
Trying to make a Projectile Rotate and Move Forward.. 1 Answer
How to make an object without Rigidbody move at the same speed as an object with Rigidbody? 1 Answer
Function with parameters, wrong values assigned 1 Answer
Object keeps orbiting target location in a Coroutine 0 Answers
How do I translate my ship left and right and have it rotate at the same time? 1 Answer