- Home /
Need help with platformer simple platform script.
Trying to create a platform that moves left, then right. The issue i am having is 1, that the tile automaticly goes to a set position regardless of where i place it once the scene plays. And 2 if the player is ontop of the tile, he must run with it or it will move out from under him.
Here is the script
//Movement Parameters.
public float moveDistance;
public float speed;
public float delayStartBy = 0;
private bool go;
void Start()
{
StartCoroutine(WaitTime());
}
void Update()
{
if (go)
{
transform.position = new Vector3(Mathf.PingPong(Time.time * speed, moveDistance),transform.position.y, transform.position.z);
}
}
yeah, that is because you are setting the position of the transform. The moment you start up your game it is set to the value of what ever $$anonymous$$ath.PingPong returns. You should consider moving the Transform with either Vector3.$$anonymous$$oveTowards or, even better, put a Rigidbody component on the platform and move it by adding Force.
you should give a Rigidbody component to your player too, so that it sticks to the platform (by setting drag>0)
I tried that and it didnt work. Soon as i jumped on the platform it went crazy. So I upped the $$anonymous$$ass property on the platform and that solved the crazy spiral. But the player doesn't move with it still.
Your answer
Follow this Question
Related Questions
2D 360 degress platformer example needed 0 Answers
How to make Rigidbody.AddForce less delayed in Unity3D? 0 Answers
How do I change the properties of a Component in a Parent Object? 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers