From 94842617394a0f357aca01b338168aae52204ef9 Mon Sep 17 00:00:00 2001 From: Jef D Date: Mon, 6 Mar 2023 10:46:17 +0100 Subject: [PATCH] Clarify reasons for physics processes (#6825) --- tutorials/physics/physics_introduction.rst | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tutorials/physics/physics_introduction.rst b/tutorials/physics/physics_introduction.rst index 6f75e1108..d8e031caf 100644 --- a/tutorials/physics/physics_introduction.rst +++ b/tutorials/physics/physics_introduction.rst @@ -26,7 +26,8 @@ In this guide, you will learn: Collision objects ----------------- -Godot offers four kinds of physics bodies, extending :ref:`CollisionObject2D `: +Godot offers four kinds of collision objects which all extend :ref:`CollisionObject2D `. +The last three listed below are physics bodies and additionally extend :ref:`PhysicsBody2D `. - :ref:`Area2D ` ``Area2D`` nodes provide **detection** and **influence**. They can detect when @@ -34,8 +35,6 @@ Godot offers four kinds of physics bodies, extending :ref:`CollisionObject2D `: - - :ref:`StaticBody2D ` A static body is one that is not moved by the physics engine. It participates in collision detection, but does not move in response to the collision. They @@ -45,7 +44,8 @@ The other three bodies extend :ref:`PhysicsBody2D `: - :ref:`RigidBody2D ` This is the node that implements simulated 2D physics. You do not control a ``RigidBody2D`` directly, but instead you apply forces to it (gravity, impulses, - etc.) and the physics engine calculates the resulting movement. :ref:`Read more about using rigid bodies. ` + etc.) and the physics engine calculates the resulting movement. + :ref:`Read more about using rigid bodies. ` - :ref:`CharacterBody2D ` A body that provides collision detection, but no physics. All movement and @@ -83,15 +83,19 @@ These nodes allow you to draw the shape directly in the editor workspace. Physics process callback ~~~~~~~~~~~~~~~~~~~~~~~~ -The physics engine may spawn multiple threads to improve performance, so -it can use up to a full frame to process physics. Because of this, the value -of a body's state variables such as ``position`` or ``linear velocity`` -may not be accurate for the current frame. +The physics engine runs at a fixed rate (a default of 60 iterations per second). This rate +is typically different from the frame rate which fluctuates based on what is rendered and +available resources. -In order to avoid this inaccuracy, any code that needs to access a body's properties should -be run in the :ref:`Node._physics_process() ` -callback, which is called before each physics step at a constant frame rate -(60 times per second by default). This method will be passed a ``delta`` +It is important that all physics related code runs at this fixed rate. Therefore Godot +differentiates :ref:`between physics and idle processing `. +Code that runs each frame is called idle processing and code that runs on each physics +tick is called physics processing. Godot provides two different callbacks, one for each +of those processing rates. + +The physics callback, :ref:`Node._physics_process() `, +is called before each physics step. Any code that needs to access a body's properties should +be run in here. This method will be passed a ``delta`` parameter, which is a floating-point number equal to the time passed in *seconds* since the last step. When using the default 60 Hz physics update rate, it will typically be equal to ``0.01666...`` (but not always, see below).