0
\$\begingroup\$

I have made a slot machine game. The problem is that after resetting each spin, the spinning value labels get closer together until they overlap.

It seems that the problem appears the moment they stop spinning. If I keep them running infinitely without stopping, the distance between them remains stable.

This is the code attached to each value component

private void FixedUpdate()
{
    if (gameState == GameState.SPINNING)
    {
        Spin();
        if (isPrize)
        {
            /*If prize value is close to start make an extra round*/
            if (this.transform.localPosition == winTransform.localPosition)
            {
                if (firstPass)
                {
                    firstPass = false;
                }
                else
                {
                    var message = GameEvent.Create(GameState.IDLE);
                    message.Publish();
                    firstPass = true;
                }
            }
        }
    }
}

private void Spin()
{

    float step = speed * Time.fixedDeltaTime;
    /*Let it snow*/
    transform.localPosition = Vector3.MoveTowards(transform.localPosition,
        boundaryTransform.localPosition, step);
    /*Reposition when it reaches the end*/
    if (Mathf.Abs(transform.position.y - boundaryTransform.position.y) < 10)
    {
        /*-400 because of the total number of values, the respawn position and the boundary position*/
        transform.localPosition = new Vector3(0,resetPosition.y-400,0);
        
    }
    
}

Normal Before first stop

Overlapping

\$\endgroup\$

You must log in to answer this question.

Browse other questions tagged .