Hey all. I’m making a platform game with the Unity 2D tools. I have some moving platforms working, using Vector3.lerp. The problem here is when my character is on them. When the platforms move down, the character bounces up and down on it. When the platforms move up, the player does the same only less, it’s more like he’s vibrating.
From what I’ve looked into I’m thinking the issue is that the platforms move with
transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
while the character moves using 2D physics forces.
Can someone confirm if that’s the issue? And if it is, how would I go about changing my current platform script (below) to use forces?
Thanks.
void Start() {
startTime = Time.time;
journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
}
void FixedUpdate() {
if (atStartMarker){
MovePlatformDown();
}
if (atEndMarker){
MovePlatformUp();
}
}
void MovePlatformDown(){
distCovered = (Time.time - startTime) * speed;
fracJourney = distCovered / journeyLength;
platform.transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
if (platform.transform.position == endMarker.position){
//print ("Journey Down Complete");
atStartMarker = false;
atEndMarker = true;
distCovered = 0.0f;
fracJourney = 0.0f;
startTime = Time.time;
}
}
void MovePlatformUp(){
distCovered = (Time.time - startTime) * speed;
fracJourney = distCovered / journeyLength;
platform.transform.position = Vector3.Lerp(endMarker.position, startMarker.position, fracJourney);
if (platform.transform.position == startMarker.position){
//print ("Journey Up Complete");
atStartMarker = true;
atEndMarker = false;
distCovered = 0.0f;
fracJourney = 0.0f;
startTime = Time.time;
}
}