Launching The Ball

when I wrote like this :

 if (!Touchscreen.current.primaryTouch.press.isPressed) //wether the user has touch the screen or not
{
    if (isDragging)
    {
        LaunchTheBall();
    }
    else { isDragging = false; }

     
    return;
}

when I wrote like this the next Respawn ball was not attached to the Pivot.

but when I wrote like the tutor did :

 if (!Touchscreen.current.primaryTouch.press.isPressed) //wether the user has touch the screen or not
 {
     if (isDragging)
     {
         LaunchTheBall();
     }
     isDragging = false; 

      
     return;
 }

the Re-Spwan ball was attachedd to the Pivot…

I mean my qquestion is what is the reson that using “ELSE” made the Ball ddisconnectedd from Pivot ?

It’s a logical problem.
If the isDragging is true, then LaunchTheBall() is called, but then isDragging is never set to false because the only condition that would allow it to be changed to false in the first place is the else clause… so once IsDragging is true, it can never be set to false.

No matter what, we want isDragging to be false by the end of the outer if block, because once primaryTouch.press.isPressed is no longer true, we are no longer dragging.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms