summaryrefslogtreecommitdiff
path: root/servers/physics_2d
AgeCommit message (Collapse)Author
2022-07-25Remove ThreadWorkPool, replace by WorkerThreadPoolJuan Linietsky
The former needs to be allocated once per usage. The later is shared for all threads, which is more efficient. It can also be better debugged.
2022-06-20Clean up Hash Functionsreduz
Clean up and do fixes to hash functions and newly introduced murmur3 hashes in #61934 * Clean up usage of murmur3 * Fixed usages of binary murmur3 on floats (this is invalid) * Changed DJB2 to use xor (which seems to be better)
2022-05-20Add a new HashSet templatereduz
* Intended to replace RBSet in most cases. * Optimized for iteration speed
2022-05-19Use range iterators for RBSet in most casesAaron Record
2022-05-18Add motion parameter to toggle whether recovery is reported as a collisionRicardo Buring
This makes the intent explicit in each use case.
2022-05-16Replace most uses of Map by HashMapreduz
* Map is unnecessary and inefficient in almost every case. * Replaced by the new HashMap. * Renamed Map to RBMap and Set to RBSet for cases that still make sense (order matters) but use is discouraged. There were very few cases where replacing by HashMap was undesired because keeping the key order was intended. I tried to keep those (as RBMap) as much as possible, but might have missed some. Review appreciated!
2022-05-03Rename Basis get_axis to get_column, remove redundant methodsAaron Franke
2022-05-03Merge pull request #60627 from aaronfranke/rename-elementsRémi Verschelde
Rename Transform2D and Basis `elements` to `columns` and `rows` respectively
2022-05-02Style: Partially apply clang-tidy's `cppcoreguidelines-pro-type-member-init`Rémi Verschelde
Didn't commit all the changes where it wants to initialize a struct with `{}`. Should be reviewed in a separate PR. Option `IgnoreArrays` enabled for now to be conservative, can be disabled to see if it proposes more useful changes. Also fixed manually a handful of other missing initializations / moved some from constructors.
2022-04-29Rename Transform2D "elements" to "columns"Aaron Franke
2022-04-20Fix more issues found by cppcheck.bruvzg
2022-04-06Fix some issues found by cppcheck.bruvzg
2022-03-23Add protective checks for invalid handle use in BVHlawnjelly
Adds DEV_ASSERTS that will halt at runtime if the BVH is misused with invalid IDs, and adds ERR_FAIL macros to prevent calling with invalid IDs. Any such misuse is a bug in the physics, but this should flag any errors quickly.
2022-03-20Raycasts hitting from inside: return collision point in global coordinatesRicardo Buring
2022-03-16PinJoint2D: fix inertia tensor, taking center of mass into accountRicardo Buring
2022-03-06[4.x] BVH - Fix area-area collision regressionlawnjelly
Minimal approach to fixing regression whereby static areas where not detect dynamic areas.
2022-03-04Merge pull request #57630 from lawnjelly/bvh4_templated_checksRémi Verschelde
[4.x] BVH - Sync BVH with 3.x
2022-02-18In final phase of test_body_motion, move and cull AABB for body once, ↵Ricardo Buring
instead of for every shape
2022-02-16Style: Cleanup single-line blocks, semicolons, dead codeRémi Verschelde
Remove currently unused implementation of TextureBasisU, could be re-added later on if needed and ported.
2022-02-04BVH - Sync BVH with 3.xlawnjelly
Templated mask checks and generic NUM_TREES Fix leaking leaves
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-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-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-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-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-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-22Merge pull request #54124 from Uxeron/CenterOfMassRotationFixCamille Mohr-Daurat
Fix physics body rotating incorrectly around it's center of mass
2021-10-22Fix physics body rotating incorrectly around it's center of massUxeron
2021-10-22Fix RigidDynamicBody2D auto center of mass calculationPouleyKetchoupp
Should be changing the local center of mass, which is then transformed into `center_of_mass`. It was causing the center of mass to be always in (0,0) by default with multiple shapes.