I’m trying to make a moving platform that slides up and down. I’m new to Unity so this might not be the best way to do this. I need to make the platform not eccelerate so it doesn’t fly off the screen. Does anyone know a better way to do this or a way to stop acceleration?
Here is my Code:
using UnityEngine;
public class MovingPlatforms : MonoBehaviour
{
private Vector3 lowestPos;
private void Start()
{
lowestPos = transform.position;
}
private void Update()
{
if (transform.position.y >= lowestPos.y + 3)
{
GetComponent<Rigidbody2D>().gravityScale = 1;
}
if (transform.position.y <= lowestPos.y)
{
GetComponent<Rigidbody2D>().gravityScale = -1;
}
}
}