(CRASH) how do I fix my teleporter code?

I’m working on a VR game, that needs to have the Player go from one place SMOOTHLY to another, so I tried this code down below, and it Hard freezes the Unity Editor when I use it.


// Teleport target transform to ground position
public void Teleport()

{
    if (groundDetected)
    {
        timer = 50f;
        while (timer > 0)
        {
            bodyTransforn.position = Vector3.SmoothDamp(bodyTransforn.position, groundPos + lastNormal * 0.1f, ref velocityPh, travelS);
        }
        
    }
    else
    {
        Debug.Log("Ground wasn't detected");
    }
}

Blockquote

I think the while loop is locking up the game, to the point where I guess it’d crash (I’ve done this tons of times while doing silly things like procedural generation) have you tried doing something similar within the update method? I’ve never personally done any movement with VR so I’m not entirely sure how it would look.

    float closestDistanceToTarget = 0.1f; //you can set this to be whatever, 
    //0.1f is usually a good starter point for testing
    bool isTeleporting = false;

   void Start()
   {
      isTeleporting = false;
   }
    void Update()
    {
        if(isTeleporting) //Have something trigger this bool
        {
              bodyTransforn.position = 
              Vector3.SmoothDamp(bodyTransforn.position, 
              groundPos + lastNormal * 0.1f, 
              ref velocityPh, 
              travelS);

              //I assume groundPos + lastNormal * 0.1f is your target position
              if(Vector3.Distance(bodyTransform.position, groundPos + 
              lastNormal * 0.1f) < closestDistanceToTarget)
              {
                   isTeleporting = false; //We made it to our destination :D
              }
         }
    }

Yes! thank you it works now.