what is the difference between _PhysicsProcess and _Process C#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By siten0308

Hello,

i am very new to godot, and a convert from unity 5… really trying to stay with godot, but also looking at cocos2d, however so far Godot is great, but so far just doing a simple platform tutorial, and i am looking at the KinematicBody2D, attaching the script to it, wondering, what is the difference between _PhysicsProcess and _Process in C#? i assume the same concept is the same for GDScript?

also got another question, when working on the 2d platform, i try to increase my velocity.x runspeed from 500 to 1500, and i dont see any increase, i do have gravity set to 1000, then lowered it to 500, but i still dont see any improvement on my running or jumping… what is going on? this is the same code found on Using KinematicBody2D — Godot Engine (3.0) documentation in English

public class KinematicBody2D : Godot.KinematicBody2D
{
    [Export] public int RunSpeed = 1500;
    [Export] public int JumpSpeed = -400;
    [Export] public int Gravity = 500;

    Vector2 velocity = new Vector2();
    bool jumping = false;

    public override void _Ready()
    {
        // Called every time the node is added to the scene.
        // Initialization here
        
    }
	
	public void getInput()
    {
        velocity.x = 0;
        bool right = Input.IsActionPressed("ui_right");
        bool left = Input.IsActionPressed("ui_left");
        bool jump = Input.IsActionPressed("ui_select");

        if (jump && IsOnFloor())
        {
            jumping = true;
            velocity.y = JumpSpeed;
        }
        if (right)
        {
            velocity.x += RunSpeed;
        }
        if (left)
        {
            velocity.x -= RunSpeed;
        }
    }
	
	
	public override void _PhysicsProcess(float delta)
    {		
		getInput();
        velocity.y += Gravity * delta;
        if (jumping && IsOnFloor())
        {
            jumping = false;
        }
        velocity = MoveAndSlide(velocity, new Vector2(0, -1));
    }

//    public override void _Process(float delta)
//    {
//    }
}
:bust_in_silhouette: Reply From: p7f

Hi, The main loop has some steps. During what is called the processing step, the_Process function is called, and everything there gets executed. This function is executed every frame as soon as posible, but nothing guarantees that it will be called at regular delta steps. This may cause that physics bodies’s states variables (position for example) be inaccurate in this step.
That’s where _PhysicsProcess comes into play. There is another step in the main loop called the physics processing step, and there the function _PhysicsProcess gets executed, but always in constant regular delta steps (or at least is supposed to). So physics bodies’s states variables that are calculated in function of time (like position again) can be accuerately calculated. So everytime you need to access this kind of variables, you should do it in _PhysicsProcess instead of in _Process.

About the second question, it’s strange that you are not seeing any change when you change the RunSpeed variable value. Anyways, i recommend you to ask it in a different question, as the rules of this forum states. That way posts are somehow “cleaner” and it’s more likely you get help.