79127504

Date: 2024-10-25 22:57:25
Score: 0.5
Natty:
Report link

I just tested your code and for me it works fine. This is what I ended up using

public class Test : MonoBehaviour
{
    Vector2 a = new Vector2(0, 0);
    Vector2 b = new Vector2(0, 5);
    float movementSpeed = 2f;

    private void Update()
    {
        float move = Mathf.PingPong(Time.time * movementSpeed, 1);
        transform.position = Vector2.Lerp(a, b, move);
    }
}

Are you sure its the code itself that is wrong? Could it be something else in the game engine that isnt set up properly, for example, have you attached this script as a component to the object you want to move? Are there any other scripts that could affect this objects position? I dont think the issue is in this piece of code, the problem comes from somewhere else.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: MissingTime