summaryrefslogtreecommitdiff
path: root/servers/physics_2d
AgeCommit message (Collapse)Author
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-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.
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-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-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-04Script interface improvements for test body motionPouleyKetchoupp
-Physics servers test body motion use a class to hold parameters instead of multiple arguments to make it more readable and flexible since there are many options -Improved documentation for test body motion and kinematic collision -Removed read-only properties for body motion results (not handled in scripts, so they should be get_ methods only instead)
2021-09-30Use range iterators for `Map`Lightning_A
2021-09-30Remove shape metadata from 2D physics serverPouleyKetchoupp
Shape metadata was only used to get tile information when colliding with tilemaps. It's not needed anymore since there's an API in tilemap using body ids instead.
2021-09-29Rename RID's `getornull()` to `get_or_null()`Hugo Locurcio
2021-09-28Merge pull request #52754 from nekomatata/dynamic-body-modesCamille Mohr-Daurat
Clarify RigidDynamicBody modes
2021-09-28Merge pull request #52953 from nekomatata/fix-collision-recovery-depthRémi Verschelde
2021-09-27Improved logic for CharacterBody collision recovery depthPouleyKetchoupp
Allows 2D character controller to work without applying gravity when touching the ground (also more safely in 3D), and collision detection is more flexible with different safe margin values. Character body motion changes in 2D and 3D: -Recovery only for depth > min contact depth to help with collision detection consistency (rest info could be lost if recovery was too much) -Adaptive min contact depth (based on margin) instead of space parameter Extra CharacterBody changes: -2D: apply changes made in 3D for stop on slope and floor snap that help fixing some jittering cases -3D: fix minor inconsistencies in stop on slope and floor snap logic
2021-09-24Added set_active(true) to all body direct state force apply/impulses. #52915Daniel
2021-09-16Clarify RigidDynamicBody modesPouleyKetchoupp
RigidDynamicBody modes are replaced with several properties to make their usage clearer: -lock_rotation: disable body's rotation (instead of MODE_LOCKED) -freeze: no gravity or forces (instead of MODE_STATIC and MODE_KINEMATIC) -freeze_mode: Static (can be only teleported) or Kinematic (can be animated) Also renamed MODE_DYNAMIC_LOCKED to MODE_DYNAMIC_LINEAR in the physics servers.
2021-09-16Merge pull request #52668 from qarmin/cppcheck_servers_physicsCamille Mohr-Daurat
Initialize variables in servers/physics
2021-09-15Initialize variables in servers/physicsqarmin