Joshua Hecht

Joshua Hecht

  • NA
  • 8
  • 2.6k

Why is my Unity Mathf.Lerp not working?

Jun 8 2017 5:18 PM
I'm trying to make a moving platform and I've set up a script that handles the lerp of the platform, but no matter what I do I can't get the darn thing to move. The method I set up is supposed to lerp a float which will be the x-axis of the transform.
 
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
public class PlatformController : MonoBehaviour
{
float Output = 0;
float CurrentXPos;
void Start()
{
CurrentXPos = transform.position.x;
}
void Update()
{
Vector3 temp = new Vector3(PlatformMovement(), transform.position.y, transform.position.z);
transform.position = temp;
Debug.Log(Output);
}
float PlatformMovement()
{
float accumulator = .001f;
Output = Mathf.Lerp(CurrentXPos, 8f, accumulator);
accumulator += .05f; //Constant speed
return Output;
}
}
 

Answers (1)