Hello, a quick problem I’m having in my game is that, I followed a youtube tutorial on how to make a moving platform and the platform works, and does everything properly in terms of moving, but when I touch it and move on it, it stretches the player, and I cannot flip on it, as I can in the rest of the level. Here’s the entire Moving Platform Script, and the script that’s supposed to keep the player in place with it as it moves, which I think it also doesn’t do still.
// Moving Platform Script
public Transform movingPlatform;
public Transform Pos1;
public Transform Pos2;
public Vector2 newPosition;
public string currentState;
public float smooth;
public float resetTime;
// Use this for initialization
void Start ()
{
ChangeTarget();
}
// Update is called once per frame
void FixedUpdate ()
{
movingPlatform.position = Vector2.Lerp(movingPlatform.position, newPosition, smooth * Time.deltaTime);
}
void ChangeTarget()
{
if (currentState == "Moving To Position 1")
{
currentState = "Moving To Position 2";
newPosition = Pos2.position;
}
else if (currentState == "Moving To Position 2")
{
currentState = "Moving To Position 1";
newPosition = Pos1.position;
}
else if(currentState == "")
{
currentState = "Moving To Position 2";
newPosition = Pos2.position;
}
Invoke("ChangeTarget", resetTime);
}
//Hold Character Script
void OnTriggerEnter2D(Collider2D col)
{
col.transform.parent = gameObject.transform; // when something collides, making object move with object with parenting
}
void OnTriggerExit2D(Collider2D col)
{
col.transform.parent = null; // unparent object when exiting collider
}