0
\$\begingroup\$

I have implemented a simple "rocket" in 2D, it accepts UP and DOWN for acceleration and left/right for rotation. The implementation looks like this:

void Player::_physics_process(double delta)
{
    UpdateMotionFromInput(delta);
    set_velocity(motion);
    set_rotation(rotation);
    move_and_slide();
}

void Player::UpdateMotionFromInput(double delta)
{
    const Input* i = Input::get_singleton();

    double delta_v = 0;
    if (i->is_action_pressed("ui_up"))
        delta_v += acceleration * delta;
    if (i->is_action_pressed("ui_down"))
        delta_v -= acceleration * delta;
    if (i->is_action_pressed("ui_left"))
        angular_velocity -= angular_acceleration * delta;
    if (i->is_action_pressed("ui_right"))
        angular_velocity += angular_acceleration * delta;

    constexpr float pi_factor = 360.0f / 3.14f;

    rotation += angular_velocity * delta;
    angular_velocity -= SIGN(angular_velocity) * angular_dampening * delta;

    Vector2 newVec(0, -delta_v);
    motion = motion + newVec.rotated((float)(rotation));
}

Now the problem is, this still works even in the editor - if I press the arrows the rocket will start flying around my editor. There's a Process option in the node component, but that does not really work for me, for the given options, I am getting these results:

  1. When paused, Disabled - doesn't do anything ever.
  2. Inherit, Pausable, Always - always executes _process_physics

I want to process physics when the game is run, not when I'm in editor. How can I do that?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

As you are aware, the Pause Mode lets you control when the code runs with respect to, well, the pause.

But that is not about whether the code runs in the editor... For that look for the property editor_hint of the Engine singleton. The getter is is_editor_hint, which will be true on the editor. You can check editor_hint during initialization, and then call set_physics_process with true or false if you want it to be able to run or not.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .