summaryrefslogtreecommitdiff
path: root/servers/physics_3d
AgeCommit message (Collapse)Author
2022-01-20Rename or refactor macros to avoid leading underscoresOmar Polo
These are not used consistently and some can conflict with system-specific defines. While here, also delete some unused macros.
2022-01-03Update copyright statements to 2022Rémi Verschelde
Happy new year to the wonderful Godot community!
2021-12-10Merge pull request #55736 from nekomatata/physics-apply-forcesCamille Mohr-Daurat
Improve RigidDynamicBody force and torque API
2021-12-10Merge pull request #55773 from nekomatata/fix-raycast-ccdCamille Mohr-Daurat
Fix rigid body ray cast CCD in 2D and 3D Godot Physics
2021-12-10Fix rigid body ray cast CCD in 2D and 3D Godot PhysicsPouleyKetchoupp
For 2D: Raycast CCD now works the same as in 3D, it changes the body's velocity to place it at the impact position instead of generating a contact point that causes a wrong push back. For both 2D and 3D: The raycast CCD process reads and modifies body velocities, so it needs to be moved to pre_solve() instead of setup() to be processed linearly on the main thread, otherwise multithreading can cause some CCD results to be randomly lost when multiple collisions occur.
2021-12-10Improve RigidDynamicBody force and torque APIPouleyKetchoupp
Makes the API for forces and impulses more flexible, easier to understand and harmonized between 2D and 3D. Rigid bodies now have 3 sets of methods for forces and impulses: -apply_impulse() for impulses (one-shot and time independent) -apply_force() for forces (time dependent) applied for the current step -add_constant_force() for forces that keeps being applied each step Also updated the documentation to clarify the different methods and parameters in rigid body nodes, body direct state and physics servers.
2021-12-10Merge pull request #55702 from nekomatata/physics-solver-settingsRémi Verschelde
2021-12-09Handle test body motion with 0 marginPouleyKetchoupp
Margin needs to have a high enough value for test body motion to work properly (separate using the margin, move without then gather rest info with the margin again). Fixes issues with test motion returning no collision in some cases with margin equal to 0.
2021-12-07Add physics solver settings to project settingsPouleyKetchoupp
Helps with discovery and setup of physics solver settings, in a specific project settings section for both 2D and 3D. Other changes for cleanup: -Removed unused space parameters in 3D SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS -Added custom solver bias for Shape3D (same as Shape2D) -Improved documentation for solver settings
2021-12-03Update space parameters in 2D and 3DPouleyKetchoupp
Clarified space parameters for contacts and added missing ones. List of changes: -Add contact bias to space parameters -Add solver iterations to space parameters, instead of a specific physics server function -Renamed BODY_MAX_ALLOWED_PENETRATION to CONTACT_MAX_ALLOWED_PENETRATION to make it consistent with other contact parameters
2021-12-03Improve RigidDynamicBody contacts in 2D and 3DPouleyKetchoupp
Changed the algorithm for solving contacts to keep previous contacts as long as they are under the max separation threshold to keep contact impulses more consistent and contacts more stable. Also made 2D consistent with 3D and changed some default parameters: -Contact bias is now 0.8 instead of 0.3 to avoid springy contacts -Solver iterations are 16 instead of 8 by default for better stability Performance considerations: Tested with stress tests that include lots of contacts from overlapping bodies. 3D: There's no measurable difference in performance. 2D: Performance is a bit lower (close to 10% slower in extreme cases) The benefit for 2D physics to be much more stable outweighs the slight decrease in performance, and this could be alleviated by changing the algorithm to use jacobians for contact solving to help with cache efficiency and memory allocations.
2021-11-25Fix RigidDynamicBody gaining momentum with bouncePouleyKetchoupp
Bounce calculation now uses the previous frame's velocity, so it's consistent with the actual motion of the bodies involved and not the yet-to-be-applied forces. When bounce is 1, using the current velocity was causing the new forces (including gravity) to be taken into account, which lead to the bounce velocity to be higher than the falling velocity at the moment of impact, adding more and more energy over time.
2021-11-23Rename `remove()` to `remove_at()` when removing by indexLightning_A
2021-11-22Add wakeup() conditional if previous gravity was 0Brennen Green
2021-11-20Add area to moved list when changing monitorable,Marcel Admiraal
and only remove area from query when deleting pair if it was monitorable.
2021-11-18Merge pull request #55074 from nekomatata/fix-soft-body-gravityRémi Verschelde
2021-11-17Fix applied gravity on soft bodiesPouleyKetchoupp
Regression fix, gravity was accumulated between frames after some changes around area gravity calculation. Also got rid of unused member and method in soft body class.
2021-11-17Fix contact generation with backface collision disabledPouleyKetchoupp
Replaced the previous implementation for backface collision handling (in test_axis function from SAT algorithm) with much simpler logic in the collision generation phase with face shapes, in order to get rid of wrong contacts when backface collision is disabled. Now it just ignores the generated collision if the contact normal is against the face normal, with a threshold to keep edge contacts. Added a special case for soft bodies to invert the collision instead of ignoring it, because for now it's the best solution to avoid soft bodies to go through concave shapes (they use small spheres). This might be replaced with a better algorithm for soft bodies later.
2021-11-17Fix rest_info returning no result with high margin and low motionPouleyKetchoupp
Apply the same logic as in test_body_motion to make sure the minimum allowed depth doesn't filter out all contacts in this case.
2021-11-16Merge pull request #55036 from nekomatata/bvh-fix-updateCamille Mohr-Daurat
Fix physics BVH pairing for teleported or fast moving objects
2021-11-16Fix physics BVH pairing for teleported or fast moving objectsPouleyKetchoupp
Updating the broadphase to find new collision pairs was done after checking for collision islands, so it was working in most cases due to the pairing margin used in the BVH, but in case of teleported objects the narrowphase collision could be skipped. Now it's done before checking for collision islands, so we can ensure that broadphase pairing has been done at the same time as objects are marked as moved so their collision can be checked properly. This issue didn't happen in the Octree/HashGrid because they do nothing on update and trigger pairs directly when objects move instead.
2021-11-16Rename built-in `SGN()` macro to `SIGN()`Hugo Locurcio
This matches the name of the GDScript function (except it's uppercase here).
2021-11-11Merge pull request #54810 from nekomatata/area-separate-override-modesCamille Mohr-Daurat
Separate space override modes for gravity/damping in Area
2021-11-10Add raycast options to hit when starting inside / hit back facesPouleyKetchoupp
Makes the results consistent for all shape types with options to set the desired behavior.
2021-11-10Fix errors in CharacterBody when floor is destroyed or removedPouleyKetchoupp
In all physics servers, body_get_direct_state() now silently returns nullptr when the body has been already freed or is removed from space, so the client code can detect this state and invalidate the body rid. In 2D, there is no change in behavior (just no more errors). In 3D, the Bullet server returned a valid direct body state when the body was removed from the physics space, but in this case it didn't make sense to use the information from the body state.
2021-11-09Separate space override modes for gravity/damping in AreaPouleyKetchoupp
Also make inspector clearer for gravity point properties.
2021-11-08Merge pull request #54134 from nekomatata/body-center-of-mass-localCamille Mohr-Daurat
Expose local center of mass in physics servers
2021-11-08Expose local center of mass in physics serversPouleyKetchoupp
Center of mass in body's local space is more useful than the transformed one in some cases, like drawing its position for debug. It's especially useful to get the generated local center of mass when in auto mode (by default). Physics Server BODY_PARAM_CENTER_OF_MASS: Now always returns the local center of mass, instead of setting a local center of mass and getting a transformed one. This causes compatibility breaking, but it makes more sense for the parameter to be consistent between getter and setter. Direct Body State: There are now two properties, because both of them can be useful in different situations. center_of_mass: relative position in global coordinates (same as before) center_of_mass_local: position in local coordinates
2021-11-08Merge pull request #54486 from ibrahn/thread-work-pool-lazierRémi Verschelde
2021-11-05Rename AABB `get_area` to `get_volume`Brian Semrau
2021-11-05Merge pull request #54642 from BoilingFusion/masterCamille Mohr-Daurat
Fix the volume calculation for cylinders
2021-11-05Fix the volume calculation for cylindersJulian Adamse
2021-11-04Use parameter classes instead of arguments for all physics queriesPouleyKetchoupp
Same as what is already done for shape queries, applied to point and ray queries. Easier to document and more flexible to add more parameters. Also expose intersect_point method to script in 3D. Remove intersect_point_on_canvas in 2D, replaced with a parameter.
2021-11-01Use `Callable` in Area monitor callbackrafallus
2021-11-01ThreadWorkPool no longer starts worker threads if given zero work.Ibrahn Sahir
2021-11-01Merge pull request #37880 from nekomatata/rigid-body-damping-overrideCamille Mohr-Daurat
Improved RigidDynamicBody linear/angular damping override
2021-10-28clang-format: Various fixes to comments alignment from `clang-format` 13Rémi Verschelde
All reviewed manually and occasionally rewritten to avoid bad auto formatting.
2021-10-28clang-format: Disable alignment of operands, too unreliableRémi Verschelde
Sets `AlignOperands` to `DontAlign`. `clang-format` developers seem to mostly care about space-based indentation and every other version of clang-format breaks the bad mismatch of tabs and spaces that it seems to use for operand alignment. So it's better without, so that it respects our two-tabs `ContinuationIndentWidth`.
2021-10-25Improved RigidDynamicBody linear/angular damping overridePouleyKetchoupp
Damping values are now non-negative. Add new properties linear_damp_mode and angular_damp_mode to set the way RigidDynamicBody and PhysicalBone (2D & 3D) use damping values. It can now be Combine (default) to add to the default/areas, or Replace to override the value completely (current behavior).
2021-10-25Refactored Node3D rotation modesreduz
* Made the Basis euler orders indexed via enum. * Node3D has a new rotation_order property to choose Euler rotation order. * Node3D has also a rotation_mode property to choose between Euler, Quaternion and Basis Exposing these modes as well as the order makes Godot a lot friendlier for animators, which can choose the best way to interpolate rotations. The new *Basis* mode makes the (exposed) transform property obsolete, so it was removed (can still be accessed by code of course).
2021-10-21Fix RigidDynamicBody collision update after changing collision layer/maskPouleyKetchoupp
Changing the collision layer of a sleeping body was not triggering area updates correctly. Bodies need to be active for collision to be checked against already overlapping bodies and areas. Neighbors need to be activated too in order to handle the case where a static body is modified (it can't be activated directly but paired bodies need to check their collision again). In 3D, moved the call to wakeup() from the physics server to GodotBody3D::_shapes_changed to make it consistent with 2D and also handle the case where shapes are modified (_shapes_changed is called in both this case and collision layer changes).
2021-10-21Fix SoftDynamicBody3D crash when setting disable modePouleyKetchoupp
Proper logic for changing physics state when disabled and disabled mode is changed (it was unnecessarily making calls to re-initialize physics). Extra error handling in soft body implementations to avoid crashes with invalid mesh.
2021-10-19Fix 2D center of mass not updated from transformPouleyKetchoupp
Same logic as what was done in 3D, applied to 2D center of mass. Also did some minor cleanup in 3D and fixed center of mass transform during the first frame after teleporting a dynamic body.
2021-10-18Rename Godot Physics classes from *SW to Godot*PouleyKetchoupp
Also moved MT physics server wrappers to the main servers folder, since they don't have to be implementation specific.
2021-10-15Swap args of Plane(point, normal) constructormennomax
Now (normal, point)
2021-10-05Merge pull request #53420 from nekomatata/fix-tilemap-moving-platformRémi Verschelde
2021-10-04Merge pull request #53365 from danger-dan/wakeup_fixCamille Mohr-Daurat
Use wakeup() function to wake sleeping bodies on impulse, force and velocities. Fix for PR #52967
2021-10-05Changed from directly waking bodies to using the wakeup() functions in ↵Daniel
direct body state changes (forces, impulses and veloicities). this 'bug' was introduced in PR #52967 added wakeup to 2d direct body
2021-10-04Fix physics glitch with TileMap moving platformsPouleyKetchoupp
Added a parameter in test_body_motion to exclude attached objects from collision, used to avoid collision with all TileMap tiles with moving platform motion instead of just the one tile the character touches. Same changes made in 3D for consistency, and handling potential similar cases.
2021-10-04Merge pull request #53280 from nekomatata/test-body-motion-parametersRémi Verschelde