basically want to try add an offset to a moving sprite that moves back and forth between two point, for example a moving platform that moves between 0 and 3 on the x axes but I want that object to start at 1 on the x axes, not sure how to achieve it as it always starts at the pingpong’s start position.
thinking it’s either got something to do with the startPos variable or Time.time synchronizing the pingpong
function Start() {
rb2D = GetComponent.<Rigidbody2D>();
startPos = rb2D.position;
if(target.x == rb2D.position.x && speedX == 0)
{
target.x = 1;
}
if(target.y == rb2D.position.y && speedY == 0)
{
target.y = 1;
}
dif = target- rb2D.position;
sx = Mathf.Sign(dif.x);
sy = Mathf.Sign(dif.y);
}
function Update () {
rb2D.MovePosition(Vector2(startPos.x + Mathf.PingPong(Time.time * speedX, dif.x*sx)*sx, startPos.y + Mathf.PingPong(Time.time * speedY, dif.y*sy)*sy));
}