I'm working on a game that needs to predict several/many steps ahead where a RigidBody2D will go. Is there any way to, for example, advance a physics simulation for many steps and use the position at each step to build a trajectory? I know something like this could be done for projectile motion with some simple math, but the game I'm making will have difficult-to-predict physics interactions and can only really be predicted by simulating many steps ahead (i.e. see into the future).

For a little more context, imagine the trajectory indicators that show for games like angry birds, gold games, peglin, etc. That's my desired end goal, but the physics interactions are sufficiently complicated that I'm not sure how to go about it.

Yes. What you need to do is create a second (fake) body with the same collision properties as the real one, but that you run at a different speed.

You can override the function _integrate_forces and then set custom_integrator to true.

https://docs.godotengine.org/en/stable/classes/class_rigidbody2d.html#class-rigidbody2d-method-integrate-forces

In that function you can do basically whatever you want with the physics state, like changing the delta and moving multiple times.

    cybereality

    Do you know how to actually advance the physics body by a step? In the _integrate_forces function, I essentially want to do something like this (pardon my mixed psuedocode):

    predicted_path = [ ]
    for (int i = 0; i < 100; i++) {
      // Compute one physics step - This is what I'm unsure how to do
      ???
      // Then add predicted path position, building a "line" of positions as the object is simulated
      predicted_path.append(position);
    }
    // draw predicted path using Line2D - this part I have no problem with

    I seem to have access to Physics2DDirectBodyState, and presumably to the physics 2d server singleton if I want.

    If it makes any difference, I'm writing my project in C# -- but I've never had issues converting from GDScript help/advice to C#

    Actually, it's more complex than I thought. For some reason I recall writing some code for this before, but I think I calculated the trajectory by hand.

    I did find this function which looks useful body_test_motion. But it does not appear to run the physics step, just check for collision.

    https://docs.godotengine.org/en/stable/classes/class_physics2dserver.html#class-physics2dserver-method-body-test-motion

    Though I guess you could use your own trajectory code and simply using the above function of collision detection. However, this would not account for rotation or bouncing, so it will be limited.