# Making object move from left to right?

Hey everybody i´m currently making a ball rolling game.

I´m looking for how to make a platform move from the left to the right.
So when it etc. hits the X position 10, it will move to X - 10 and then repeat.

I currently have a script but the issue is that whenever it hits its max position to the right it makes a very hard transition to moving to the left so the player falls off.

And whenever my player interacts with it its speed gets screwed so it moves slowly.

My Script
```javascript
**#pragma strict

var platform : Transform;
var startTransform : Transform;
var endTransform : Transform;
var platformSpeed : float;

var direction : Vector3;
var destination : Transform;

function Start()
{
SetDestination(startTransform);
}

function FixedUpdate ()
{
platform.GetComponent.().MovePosition(platform.position + direction * platformSpeed * Time.fixedDeltaTime);

``````if(Vector3.Distance(platform.position, destination.position) < platformSpeed * Time.fixedDeltaTime)
{
SetDestination(destination == startTransform ? endTransform : startTransform);
}
``````

}

function OnDrawGizmos()
{
Gizmos.color = Color.green;
Gizmos.DrawWireCube(startTransform.position, platform.localScale);

``````Gizmos.color = Color.red;
Gizmos.DrawWireCube(endTransform.position, platform.localScale);
``````

}

function SetDestination(dest : Transform)
{
destination = dest;
direction = (destination.position - platform.position).normalized;

}**
```

You could just subtract or add onto the x value through a Vector3.

public float subtractSpeed; //Move speed
public float maxAmount; //The maxed amount
public bool hitTheEnd; //Has the platform hit the max Value?
public float maxLeftValue;
public float maxRightValue;

public FixedUpdate(){

float moreSubtract;
moreSubtract = subtractSpeed * Time.deltaTime;
if(hitTheEnd == false){
maxAmount -= moreSubtract;
if(transform.position.x > maxLeftValue){
transform.position = new Vector3(maxAmount,0,0);
}
else{
hitTheEnd = true;
}
}
else{
maxAmount += moreSubtract;
if(transform.position.x < maxRightValue){
transform.position = new Vector3(maxAmount,0,0);
}
else{
hitTheEnd = false;
}
}

Let me know if this works! I haven’t tested it!

Hey i´ve put it into unity now, but there is a parsin error somewhere but i cant find it, can you help me?

Btw i dont use Csharp but i use JS, but ill try it anyway

``````using UnityEngine;
using System.Collections;

public float : subtractSpeed;
public float : maxAmount;
public bool : hitTheEnd;
public float : maxLeftValue;
public float : maxRightValue;

public FixedUpdate()
{

float moreSubtract;

moreSubtract = subtractSpeed * Time.deltaTime;
if(hitTheEnd == false)
{
maxAmount -= moreSubtract;
if(transform.position.x > maxLeftValue)
{
transform.position = new Vector3(maxAmount,0,0);
}
else
{
hitTheEnd = true;
}
}
else
{
maxAmount += moreSubtract;
if(transform.position.x < maxRightValue)
{
transform.position = new Vector3(maxAmount,0,0);
}
else
{
hitTheEnd = false;
}
}
}
``````

What parser error does it give you?

i tried something else, i have now tried using the animation option and a simple script which looks like this.

``````function GoRight()
{

}
function GoLeft()
{