# Trying to get object from point A to point B on x axis and respawn at starting point

Hello, I’m new to unity and i have a basic question using JavaScript. Im trying to get my place holder to “roll” across the screen on the “X” axis in front of the camera. It will actually be a car when we get the sprite on it but my question is whats the best way to do this because when the “car” gets to the end i want it to re-spawn to where it begun and do the same thing over again. I’m new to coding and i’ve used a few scripts so far and none of them worked or even had the car move across the screen. Please any help or references would help! Thanks in advance!

// Transforms to act as start and end markers for the journey.
var startMarker: Transform;
var endMarker: Transform;

// Movement speed in units/sec.
var speed = 1.0;

// Time when the movement started.
private var startTime: float;

// Total distance between the markers.
private var journeyLength: float;

var target : Transform;
var smooth = 5.0;

function Start() {
// Keep a note of the time the movement started.
startTime = Time.time;

// Calculate the journey length.
journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
}

// Follows the target position like with a spring
function Update () {
// Distance moved = time * speed.
var distCovered = (Time.time - startTime) * speed;

// Fraction of journey completed = current distance divided by total distance.
var fracJourney = distCovered / journeyLength;

// Set our position as a fraction of the distance between the markers.
transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
}

this is the code im using and im getting an error saying UnassignedReferenceException: The variable startMarker of ‘Truck’ has not been assigned.
You probably need to assign the startMarker variable of the Truck script in the inspector.
UnityEngine.Transform.get_position () (at C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/Editor/UnityEngineTransform.cs:26)
Truck.Update () (at C:/Users/game/Desktop/J-Walking/Jay Walking/Assets/Truck.js:34)

update … its now telling me this, i think its asking for coordinates?

transform.position assign attempt for ‘Cube’ is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.Transform:set_position(Vector3)
Truck:Update() (at Assets/Truck.js:34)

Use code tags and post line numbers. As far as the error is concerned you are getting a “Not a Number error”. Usually they come from a zero value some place. Try the fracJourney first with something like:

``````// Set our position as a fraction of the distance between the markers.
if(fracJourney != 0){
transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
}
``````

either that or you didn’t drag the transform onto the script for startMarker and endMarker, but you probably would have got an error some place else for that.