Problem of Translation

Hi guys!

I have a little problem with my script which consists to make a kind of plateform.

This script allows an object to move (like Sinusoïdal behavior, or Linear…), and if another object comes on this one, it will have exactly the same movement.

Here is the script which makes the plateform and objects on this one moving Linearly :

float prevX = this.sens * this.speed * Time.deltaTime;

gameObject.transform.Translate(prevX,
                               prevX * this.coeficientA,
                               0, Space.World);


foreach (GameObject it in this.objOnPlateForme)
{
    it.transform.Translate(prevX,
                           prevX * this.coeficientA,
                           0, gameObject.transform);
}

this.sens represents the direction of the plateform movement (-1 or 1), this.speed the speed of the plateform and this.objOnPlateForme the container which contains the objects.

The problem is that the object of the container doesn’t move exactly like the plateform. I don’t really understand because the value of X and Y are exactly the same, but the objects on it move little bit slower than the plateform.

Do any one know an issue?

A possible workaround could be to store the difference the platform travels between each tick and offset each object by the distance traveled. It’s just an idea I haven’t tried it sorry.

float prevX = this.sens * this.speed * Time.deltaTime;


//Store the current position of the platform
Vector3 startPos = gameObject.Transform.position;

//Move the platform
gameObject.transform.Translate(prevX,
                               prevX * this.coeficientA,
                               0, Space.World);


//Store the current position of the platform
Vector3 endPos = gameObject.transform.position;


//The difference between the two vectors
Vector3 offset = new Vector3 (EndPos.x - StartPos.x, EndPos.y - StartPos.y, EndPos.z - StartPos.z);


//Offset the objects
foreach (GameObject it in this.objOnPlateForme)
{
    it.transform.position += offset;
}

Hi!

I finally find what make the objects moving slower. It is because of the gravity of Unity. I must do my own gravity and not use the gravity of unity to have the behavior i was expected.

Thanks for your help!