summaryrefslogtreecommitdiff
path: root/servers/physics_2d
AgeCommit message (Collapse)Author
2021-08-31Merge pull request #49471 from nekomatata/body-state-sync-callbackJuan Linietsky
Clean physics direct body state usage in 2D and 3D physics
2021-08-28Merge pull request #52070 from nekomatata/area-point-gravity-fixFabio Alessandrelli
Fix point gravity calculation
2021-08-27Optimize area detection and intersect_shape queries with concave shapesPouleyKetchoupp
Whenever contact points are not needed, collision checks with concave shapes (triangle mesh and heightmap) stop at the first colliding triangle.
2021-08-27Merge pull request #51896 from nekomatata/restore-ray-shapeCamille Mohr-Daurat
Refactor RayShape and rename to SeparationRayShape
2021-08-26Merge pull request #51801 from nekomatata/area-one-directional-layer-checkCamille Mohr-Daurat
One-directional layer check for Area vs. RigidBody/SoftBody/Area
2021-08-25Clean physics direct body state usage in 2D and 3D physicsPouleyKetchoupp
Use a C++ callback instead of Callable for synchronizing physics nodes' state with physics servers. Remove usage of PhysicsDirectBodyState in physics nodes when not necessary. Store PhysicsDirectBodyState for bodies individually instead of a singleton to avoid issues when accessing direct body state for multiple bodies. PhysicsDirectBodyState is initialized only when needed, so it doesn't have to be created when using the physics server directly. Move PhysicsDirectBodyState2D and PhysicsDirectBodyState3D to separate cpp files.
2021-08-24Rename RayShape to SeparationRayShapePouleyKetchoupp
Makes it clearer that it's used for special cases when picking a collision shape.
2021-08-24Rename slips_on_slope to slide_on_slopePouleyKetchoupp
Also added some precision to the documentation.
2021-08-24Fix CharacterBody motion with RayShapePouleyKetchoupp
Make separation ray shapes work properly in move_and_slide, wihtout the specific code in CharacterBody like before. Now most of the logic is handled inside the physics server. The only thing that's needed is to use ray shapes only for recovery and ignore them when performing the motion itself (unless we're snapping or slips on slope is on).
2021-08-24Fix RayShape collision detectionPouleyKetchoupp
One-way collision is disabled for both rigid bodies and character bodies. Kinematic margin is now applied to ray shapes to help getting consistent results in slopes and flat surfaces. Convex shapes don't return inverted normals when a segment test starts inside (raycasting will be made consistent in a separate patch). Ray shapes also discard contacts when fully contained inside a shape and when the contact direction is inverted, so the behavior is consistent with all shape types. Now they always separate only when intersecting the top of a shape (for downward rays).
2021-08-24Restore RayShape as a regular shape typePouleyKetchoupp
Partial revert from previously removing ray shapes completely, added back as a shape type but without the specific character controller code.
2021-08-24Fix point gravity calculationPouleyKetchoupp
Removing the + 1 in point gravity formula when using distance scale to make it more accurate for standard gravitation. Fixes precession in orbits for games using gravitation. Also moved gravity calculation to area to use it for both rigid bodies and soft bodies in 3D (same change in 2D for consistency). Co-authored-by: Ryan Peach <ryan.peach@keysight.com>
2021-08-19Fix compilation warnings in Shape2DSW/Shape3DSWPouleyKetchoupp
2021-08-17One-directional layer check for Area vs. RigidBody/SoftBody/AreaPouleyKetchoupp
Same thing that was already done for rigid body and character body collision detection.
2021-08-15API improvement on physics, mainly CharacterBodyfabriceci
Changes: - Rename few methods/property and group them in the editor when it's possible - Make MotionResult API consistency with KinematicCollision - Return a boolean in move_and_slide if there was a collision - New methods: - get_floor_angle on CharacterBody to get the floor angle. - get_angle on KinematicCollision to get the collision angle. - get_last_slide_collision to quickly get the latest collision of move_and_slide.
2021-08-14Rename LineShape2D to WorldMarginShape2DHugo Locurcio
The new name makes it more obvious that it acts as an infinite plane, and is consistent with its 3D counterpart (WorldMarginShape3D).
2021-08-11Make radius & height in CapsuleShape2D independentTomasz Chabora
2021-08-10Remove infinite inertia and ray shapes from CharacterBodyPouleyKetchoupp
Infinite inertia: Not needed anymore, since it's now possible to set one-directional collision layers in order for characters to ignore rigid bodies, while rigid bodies still collide with characters. Ray shapes: They were introduced as a work around to allow constant speed on slopes, which is now possible with the new property in CharacterBody instead.
2021-08-09Fix applied rotation from moving platforms in move_and_slidePouleyKetchoupp
When synchronizing CharacterBody motion with moving the platform using direct body state, only the linear velocity was taken into account. This change exposes velocity at local point in direct body state and uses it in move_and_slide to get the proper velocity that includes rotations.
2021-07-31Merge pull request #50625 from nekomatata/body-one-direction-layersRémi Verschelde
One-directional collision layer check for rigid bodies and soft bodies
2021-07-25Use const references where possible for List range iteratorsRémi Verschelde
2021-07-23Use C++ iterators for Lists in many situationsAaron Franke
2021-07-19One-directional collision layer check for rigid bodies and soft bodiesPouleyKetchoupp
Check for each body individually if it collides with the other one or ignores it. When a body is being ignored, the other body's mass is considered infinite when applying impulses to avoid extra overlapping.
2021-07-19Ensure KinematicBodies only interact with other Bodies with matching mask.Marcel Admiraal
2021-07-15Fixing 2D moving platform logicfabriceci
Fixing by applying the movement in two steps, first the platform movement, and then the body movement. Plus, add the platform movement when we are on_wall.
2021-07-13Merge pull request #50063 from nekomatata/more-accurate-move-and-slideRémi Verschelde
Make move_and_slide collision detection more accurate
2021-07-02Expose body_test_motion in 3D physics serverPouleyKetchoupp
Results are exposed through PhysicsTestMotionResult3D, the same way it's done for 2D. Also cleaned a few things in the 2D version.
2021-07-01Make move_and_slide collision detection more accuratePouleyKetchoupp
More accurate unsafe motion calculation * Safe and unsafe motion are calculated by dichotomy with a limited number of steps. It's good for performance, but on long motions that either collide near the beginning or near the end, the result can be very imprecise. * Now a factor 0.25 or 0.75 is used to converge faster when this case happens, which allows longer motions to get more accurate collision detection. * Makes snap collision more precise, and helps with cases where diagonal collision on the border of a platform can lead to the character being stuck. Additional improvements to move_and_slide: * Handle slide canceling in move_and_collide with 0 velocity instead of not applying it. * Better handling of snap with custom logic to cancel sliding. * Remove small jittering when using stop on slope, by canceling the motion completely when the resulting motion is less than margin instead of always projecting to the up direction (in both body motion and snap). Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-06-30Merge pull request #49844 from nekomatata/physics-disabled-shapesRémi Verschelde
Fix and clean disabled shapes handling in godot physics servers
2021-06-28Fix move_and_collide causing sliding on slopesPouleyKetchoupp
Make sure the direction of the motion is preserved, unless the depth is higher than the margin, which means the body needs depenetration in any direction. Also changed move_and_slide to avoid sliding on the first motion, in order to avoid issues with unstable position on ground when jumping. Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-06-22Fix and clean disabled shapes handling in godot physics serversPouleyKetchoupp
In 3D, disabled shapes are now not added to the broadphase anymore. Since they are removed right away when disabled, no need to check for disabled shapes for any query that comes from the broadphase. Also Fixes raycast queries returning disabled shapes. In 2D, disabled shapes where already not added to the broadphase. Remove the same unnecessary checks as in 3D. Overall harmonized API for disabled shapes in the physics servers and removed duplicate method.
2021-06-09Refactor CommandQueueMTreduz
* RingBuffer had no reason to be in this context * A single buffer is used that can grow as much as the game needs. This should make thread loading entirely reliable.
2021-06-04Safe margin cleanupPouleyKetchoupp
Safe margin property on CharacterBody only, used as argument in move_and_collide. Removed kinematic_safe_margin in 3D physics server, not really useful and now harmonized with 2D.
2021-06-04More explanatory names for RigidBody modesPouleyKetchoupp
MODE_DYNAMIC instead of MODE_RIGID MODE_DYNAMIC_LOCKED instead of MODE_CHARACTER No more special case for sleeping behavior for MODE_DYNAMIC_LOCKED (MODE_CHARACTER was forcing the body not to sleep, which is redundant with can_sleep and wasn't done in Bullet).
2021-06-03Rename Vector2 clamped to limit_length and add limit_length to Vector3Aaron Franke
2021-05-19Enable setting of collision iterations in PhysicsServer2DRhathe
This allows fine-tuning of collision iterations for more accurate collision physics with a performance cost.
2021-05-10Dynamic BVH broadphase in 2D & 3D Godot PhysicsPouleyKetchoupp
Port lawnjelly's dynamic BVH implementation from 3.x to be used in both 2D and 3D broadphases. Removed alternative broadphase implementations which are not meant to be used anymore since they are much slower. Includes changes in Rect2, Vector2, Vector3 that help with the template implementation of the dynamic BVH by uniformizing the interface between 2D and 3D math. Co-authored-by: lawnjelly <lawnjelly@gmail.com>
2021-04-26Godot Physics collisions and solver processed on threadsPouleyKetchoupp
Use ThreadWorkPool to process physics step tasks in multiple threads. Collisions are all processed in parallel and solving impulses is processed in parallel for rigid body islands. Additional changes: - Proper islands for soft bodies linked to active bodies - All moving areas are on separate islands (can be parallelized) - Fix inconsistencies with body islands (Kinematic bodies could link bodies together or not depending on the processing order) - Completely prevent static bodies to be active (it could cause islands to be wrongly created and cause dangerous multi-threading operations as well as inconsistencies in created islands) - Apply impulses only on dynamic bodies to avoid unsafe multi-threaded operations (static bodies can be on multiple islands) - Removed inverted iterations when populating body islands, it's now faster in regular order (maybe after fixing inconsistencies)
2021-04-22Unexpose _direct_state_changed in PhysicsBodyrafallus
Removed _direct_state_changed bindings Affects 2D and 3D nodes Callbacks now use Callable Tests were changed accordingly
2021-04-16Merge pull request #47942 from nekomatata/joint-check-body-typesRémi Verschelde
Fix errors related to joints setup with two non-dynamic bodies
2021-04-15Fix errors related to joints setup with two non-dynamic bodiesPouleyKetchoupp
2021-04-15Optimize BroadPhase2dHashGrid to not pair elements on different layersHenry Conklin
Clean up logic in _check_motion Closes 45824
2021-04-12Godot Physics solver optimizationPouleyKetchoupp
Several optimizations in the way solver islands are processed in both 2D and 3D physics: - Use LocalVector instead of linked list to avoid cache misses (with persistent storage based on worst case scenario) - Remove pairs when setup fails (no valid contact) to avoid unnecessary solving of non-colliding rigid bodies just to return immediately
2021-04-06Merge pull request #47678 from madmiraal/fix-47436.1Rémi Verschelde
Check for empty ConcavePolygonShape2D before checking for intersection
2021-04-06Merge pull request #47675 from madmiraal/fix-47436Rémi Verschelde
Check ConvexPolygonShape2D point count before calcuating moment of inertia
2021-04-06Check for empty ConcavePolygonShape2D before checking for intersectionMarcel Admiraal
2021-04-06Check ConvexPolygonShape2D point count before calcuating moment of inertiaMarcel Admiraal
2021-04-06Ensure ConvexPolygonShape support count variable is initialisedMarcel Admiraal
2021-03-26Merge pull request #44695 from madmiraal/fix-44632Rémi Verschelde
Remove all elements from monitored_bodies and monitored_areas when processed
2021-03-11Fix GodotPhysics solver with kinematic body set to report contactsPouleyKetchoupp
In 3D, collision is disabled between kinematic/static bodies when contacts are generated only to report them. In 2D, this case was already fixed but the code is cleaned to make it easier to follow.