Hi, I have a logical issue where my block would get stuck on a corner on repeat at times when it is moving left and right within the int range limit of 1.8f to -1.8f, I’ve tried everything but nothing works, I’m at a lost, I would be really grateful for whoever could resolve this issue that I am currently have right now. I will provide screenshots on the following to make the issue clearer.
private float min_X = -1.8f, max_X = 1.8f;
public float blockSpeed = 2f;
float blockSpeedForLeftRight = 1f;
private bool canMove;
public static float move_Speed = 2f;
void Start()
{
canMove = true;
}
void Update()
{
MoveBox();
}
void MoveBox()
{
if(canMove)
{
Vector3 temp = transform.position;
if (temp.x >= max_X)
{
move_Speed *= -blockSpeedForLeftRight;
}
else if (temp.x <= min_X)
{
move_Speed *= -blockSpeedForLeftRight;
}
temp.x += move_Speed * Time.deltaTime;
transform.position = temp;
}
}
}