Search Unity

How To Instantiate Image With Acceleration

Discussion in 'Editor & General Support' started by MORIBOND, Jul 6, 2020.

  1. MORIBOND

    MORIBOND

    Joined:
    Jun 23, 2020
    Posts:
    13
    Hello everybody,

    I try to clone squares and keep distance between them but i don't success. So i move the blue squares with a mouse drag and i clone them with this code:

    Code (CSharp):
    1. public void OnTriggerEnter2D(Collider2D collider)
    2.     {
    3.  
    4.        
    5.  
    6.        
    7.         var instantiatedClone = Instantiate(collider.gameObject, PortalSpawnPoint.position, Quaternion.identity, collider.transform);
    8.         instantiatedClone.gameObject.GetComponent<Move>().enabled = false;
    9.  
    10.     }
    The image attached give more informations.

    I guess i have to introduce time on my code but i don't know how, can you help me?

    Thank you in advance.
     

    Attached Files:

  2. MORIBOND

    MORIBOND

    Joined:
    Jun 23, 2020
    Posts:
    13
    In fact, i'm not sure if the acceleration is the problem.

    If i print the x position each time a square is colliding, i can see that the position is not the same when the speed is high, so i guess the OnTriggerEnter2D is too slow and detect the collision when the square has moved.

    Do you have any tips to me?

    Thank you.