Search Unity

Move Position X And Y Positions

Discussion in 'Scripting' started by imunirbesye, Feb 3, 2019.

  1. imunirbesye

    imunirbesye

    Joined:
    Oct 27, 2018
    Posts:
    57
    I want to move my player with jump but I can't. I am makimg a mistake but I can't find it.

    Code (CSharp):
    1. IEnumerator MoveFromTo(Transform objectToMove, Vector3 a, Vector3 b, float speed)
    2.     {
    3.         float step = (speed / (a - b).magnitude) * Time.fixedDeltaTime;
    4.         float t = 0;
    5.         float xOrtaNokta;
    6.         Vector3 midDestination;
    7.  
    8.         midDestination.x = b.x;
    9.         midDestination.y = b.y;
    10.         midDestination.z = b.z;
    11.  
    12.         xOrtaNokta = Mathf.Lerp(objectToMove.position.x, b.x, 0.5f);
    13.  
    14.         while (t <= 1.0f)
    15.         {
    16.             if(t <= 0.5f)
    17.             {
    18.                 b.x = xOrtaNokta;
    19.                 b.y = 2f;
    20.                 t += step;
    21.                 objectToMove.position = Vector3.Lerp(a, b, t);
    22.                 print("1. "+objectToMove.position.x);
    23.                 yield return new WaitForFixedUpdate();
    24.             }
    25.             else if(t <= 1)
    26.             {
    27.                 b.x = midDestination.x;
    28.                 b.y = 0.47f;
    29.                 a.y = 2f;
    30.                 t += step;
    31.                 objectToMove.position = Vector3.Lerp(a, b, t);
    32.                 print("2."+objectToMove.position.x);
    33.                 yield return new WaitForFixedUpdate();
    34.             }
    35.         }
    36.         objectToMove.position = b;
    37.     }
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Can you please describe more, about current behaviour? What happens and when? What Debug logs print out?
     
  3. imunirbesye

    imunirbesye

    Joined:
    Oct 27, 2018
    Posts:
    57
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    You may need debug your step value.
    If steps are too big, you may get unexpected results.