- Home /
Make simple moving platform
I've looked this previously, but i can't figure out how to make a platform move a few seconds, stop, then go back. I'm using UnityScript.
What i'm using right now is
function Start ()
{
}
function Update ()
{
transform.Translate(Vector3.forward * Time.deltaTime);
}
This only makes it move forward without stopping or returning. I appreciate anyone taking the time to answer.
Answer by tanoshimi · Apr 24, 2014 at 06:53 PM
Mathf.PingPong is your friend...
Thanks i seen something like this previously but wasn't sure if it would work. I'll give it a shot.
I did this and the platform goes off of the screen any explanation why it does this?
Are you using it with translate or by setting the position (transform.position = ...)?
Yes - you set the length variable too high. Change the 3 to a 1.
Answer by sgtstrings · Apr 24, 2014 at 07:10 PM
I think you want to use a Sine or Cosine function. (I personally script in C#, but I assume it's similar to this)
transform.Translate(transform.forward*Mathf.Cos (Time.time)*Time.deltaTime);
Thank you for your comment, i have to use unityscript as its for an assignment :].