How can i move a game object up and down so it acts like a obstacle for my sphere player

the object is a cube which has to go up and come down acting like a obstacle which requires timing to complete
THANKS FOR YOUR HELP!!!

   float speed = 1f;
   float delta = 3f;  //delta is the difference between min y to max y.

   void Update() {
        float y = transform.position.y + Mathf.PingPong(speed * Time.time, delta); 
        Vector3 pos = new Vector3(transform.position.x, y, transform.position.z);
        transform.position = pos;
    }

Use the MoveTowards function

transform.position = Vector3.MoveTowards(firstPosition, endPosition, speed);

Hey

you can use a Co-Routine and use Vector3.Lerp

IEnumerator move(Transform _transform)
    {
        startPos = _transform.position;
        t = 0;

            endPos = new Vector3(startPos.x + System.Math.Sign(input.x) *  startPos.y = System.Math.Sign(input.y), startPos.z);
        

        factor = 1f;

        while (t < 1f)
        {
            t += Time.deltaTime * moveSpeed * factor;
            _transform.position = Vector3.Lerp(startPos, endPos, t);

            yield return null;
        }

        yield return 0;
    }

What`s with “$$anonymous$$”? Is it cyber attack? ":slight_smile: