Hi
I found a script here on the forums by Raiden that I tried to create a moving platform. Code:
// simple x,y,z movement over a distance
var duration = 1.0;
var is2D = true;
var posEndDistance : Vector3;
private var posStart : Vector3;
private var posEnd : Vector3;
function Start () {
posStart = transform.position;
if (is2D) { posEndDistance.z = 0.0; } // force no movement on the "z" axis
// I could have used Vector3 to assign, but this looks more readable to me
posEnd.x = transform.position.x + posEndDistance.x;
posEnd.y = transform.position.y + posEndDistance.y;
posEnd.z = transform.position.z + posEndDistance.z;
}
function Update () {
var lerp = Mathf.PingPong (Time.time, duration) / duration;
transform.position = Vector3.Lerp (posStart, posEnd, lerp);
}
I have simple cubes with rigidbody attached to them, situated on the platform. The platform itself is also just a simple cube. Problem:
-
If I don’t attach a rigidbody to the moving platform then the cubes will not move along with the platform (friction).
-
If I attach a rigidbody then the cubes will move in a jerky fashion while on the platform, sometimes falling through the actual geometry while at other times getting stuck in the platform.
Any help would be greatly appreciated!