summaryrefslogtreecommitdiff
path: root/servers/physics_2d
AgeCommit message (Collapse)Author
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
2021-09-14Rename WorldMarginShape to WorldBoundaryShapePouleyKetchoupp
2021-09-06Proper support for custom mass properties in 2D/3D physics bodiesPouleyKetchoupp
Changes: -Added support for custom inertia and center of mass in 3D -Added support for custom center of mass in 2D -Calculated center of mass from shapes in 2D (same as in 3D) -Fixed mass properties calculation with disabled shapes in 2D/3D -Removed first_integration which is not used in 2D and doesn't seem to make a lot of sense (prevents omit_force_integration to work during the first frame) -Support for custom inertia on different axes for RigidBody3D
2021-09-06Merge pull request #52271 from nekomatata/query-layer-default-maskCamille Mohr-Daurat
Harmonize default value for collision mask in ray/shape queries
2021-08-31Add AnimatableBody inherited from StaticBody for moving platformsPouleyKetchoupp
Instead of having a physics node named Static that can be either Static or Kinematic, AnimatableBody is added again as a separate node: -Inherited from StaticBody to make its usage clearer -Still separated from CharacterBody to make its usage more focused Properly implemented constant velocity for kinematic bodies in godot physics servers (induced velocity without actually moving). Also updated description for the different physics nodes to make their usage clearer.
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-30Harmonize default value for collision mask in ray/shape queriesPouleyKetchoupp
The default mask for queries was 0, 0x7FFFFFFF or 0xFFFFFFFF depending on the cases. Now always using 0xFFFFFFFF (in the form of UINT32_MAX to make it clear) in order to use all layers by default.
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