Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Physics2D.Simulate to predict trajectory with Effector2D?

Discussion in '2D' started by Mcg, Dec 1, 2018.

  1. Mcg

    Mcg

    Joined:
    Mar 28, 2012
    Posts:
    111
    Hi, I'm trying to predict the trajectory of a game object that will enter a point effector2d and am currently using Physics2D.Simulate to draw the trajectory path however it only takes into account the velocity that I have set and the point effector2d doesn't seem to be calculated.

    I'm currently using this code when in play mode, the documentation says it only predicts all physics components in edit mode is there a way to get this to work in play mode? (Though I've not tested if this is correct in edit mode yet)

    Code (CSharp):
    1.             for (int j = 0; j < InBetweenFrameSteps; j++)
    2.             {
    3.                 PreviewedObject2D.DrawLine(j + InBetweenFrameSteps * i);
    4.                 Physics2D.Simulate(TimeStep/InBetweenFrameSteps);
    5.             }