Commit graph

52 commits

Author SHA1 Message Date
PouleyKetchoupp cc39dca9f7 Rename Godot Physics classes from *SW to Godot*
Also moved MT physics server wrappers to the main servers folder, since
they don't have to be implementation specific.
2021-10-18 17:01:10 -07:00
PouleyKetchoupp 4f8d761be6 Fix physics glitch with TileMap moving platforms
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-04 12:27:42 -07:00
PouleyKetchoupp 3ae5687d48 Script interface improvements for test body motion
-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-10-04 10:49:10 -07:00
PouleyKetchoupp d0ec46be68 Remove shape metadata from 2D physics server
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-30 10:45:36 -07:00
Hugo Locurcio ba65730cbf
Rename RID's getornull() to get_or_null() 2021-09-29 23:58:02 +02:00
PouleyKetchoupp bf523a2b2a Improved logic for CharacterBody collision recovery depth
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-27 15:31:41 -07:00
fabriceci fd9e573ba6 Port 2D improvement to move and slide 3D
Co-authored-by: Camille Mohr-Daurat <pouleyketchoup@gmail.com>
2021-09-22 00:14:04 +02:00
qarmin 91257c3900 Initialize variables in servers/physics 2021-09-15 19:41:32 +02:00
PouleyKetchoupp 82ea2a7045 Proper support for custom mass properties in 2D/3D physics bodies
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-06 10:20:16 -07:00
PouleyKetchoupp 3d5dc80348 Rename RayShape to SeparationRayShape
Makes it clearer that it's used for special cases when picking a
collision shape.
2021-08-24 17:34:55 -07:00
PouleyKetchoupp aa4791735d Rename slips_on_slope to slide_on_slope
Also added some precision to the documentation.
2021-08-24 17:34:55 -07:00
PouleyKetchoupp d9720d4395 Fix CharacterBody motion with RayShape
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-24 17:34:55 -07:00
Rémi Verschelde 43440228db
Merge pull request #51645 from fabriceci/improve-physics-api
API improvement on the physics (CharacterBody and related classes)
2021-08-16 17:05:08 +02:00
Jeffrey Cochran 14640fb6c5 Enabled softbody-area collision (intersection) and enabled area-specific gravity for soft bodies. 2021-08-15 23:01:33 -04:00
fabriceci d776b6c154 API improvement on physics, mainly CharacterBody
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-15 12:53:29 +02:00
PouleyKetchoupp 4da3a87f7d Remove infinite inertia and ray shapes from CharacterBody
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-10 12:10:26 -07:00
PouleyKetchoupp ec9fed69f4 Fix 3D moving platform logic
Same thing that was already done in 2D, applies moving platform motion
by using a call to move_and_collide that excludes the platform itself,
instead of making it part of the body motion.

Helps with handling walls and slopes correctly when the character walks
on the moving platform.

Also made some minor adjustments to the 2D version and documentation.

Co-authored-by: fabriceci <fabricecipolla@gmail.com>
2021-08-09 20:21:04 -07:00
PouleyKetchoupp 940838c174 One-directional collision layer check for rigid bodies and soft bodies
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-19 17:24:04 -07:00
Marcel Admiraal b8fe576355 Ensure KinematicBodies only interact with other Bodies with matching mask. 2021-07-19 17:03:43 +01:00
PouleyKetchoupp cf1ddfdb90 Make move_and_slide collision detection more accurate
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-07-01 15:15:42 -07:00
Rémi Verschelde 24c6ee9f56
Merge pull request #49844 from nekomatata/physics-disabled-shapes
Fix and clean disabled shapes handling in godot physics servers
2021-06-30 10:08:52 +02:00
PouleyKetchoupp 9758a75221 Fix move_and_collide causing sliding on slopes
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-28 17:17:52 -07:00
PouleyKetchoupp a65cdca894 Fix and clean disabled shapes handling in godot physics servers
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-22 16:51:47 -07:00
Rémi Verschelde 9aedc020c3
Merge pull request #42636 from madmiraal/fix-infinite-inertia 2021-06-11 13:00:31 +02:00
Aaron Franke de3f6699a5
Rename Transform to Transform3D in core 2021-06-03 07:30:01 -04:00
Rémi Verschelde 900b28f6d8
Merge pull request #47130 from e344fde6bf/fix-angular-velocity-calculation
Fix kinematic angular velocity calculations
2021-03-20 21:46:02 +01:00
e344fde6bf 1c123aaf2b Fix some angular velocity calculations
The angular velocity estimate for kinematic bodies was calculated
incorrectly.  Also, fixes its use in some kinematic/rigid collision
calculations.

This fixes #47029.
2021-03-20 07:21:37 +10:00
PouleyKetchoupp d5ea4acd2d SoftBody support in GodotPhysics 3D
- Fixed SoftBody surface update with new rendering system
- Added GodotPhysics implementation for SoftBody
- Added support to get SoftBody rid to interact with the physics server
- Added support to get SoftBody bounds from the physics server
- Removed support for unused get_vertex_position and get_point_offset
from the physics server
- Removed SoftBody properties that are unused in both Bullet and
GodotPhysics (angular and volume stiffness, pose matching)
- Added RenderingServerHandler interface to PhysicsServer3D so the physics servers don't need to reference the class from SoftBody node directly
2021-03-18 09:04:17 -07:00
Marcel Admiraal b8aabe483e Apply infinite inertia checks to Godot physics 3D 2021-03-06 11:01:42 +00:00
Rémi Verschelde a930472319
Merge pull request #45863 from nekomatata/physics-queries-disabled-shapes
Fix physics queries not filtering out disabled collision shapes
2021-02-24 13:05:28 +01:00
PouleyKetchoupp cff7a69aa0 Fix test_body_motion recovery
This change makes test_body_motion more reliable when the kinematic body
recovers from being stuck.

- When recovery occurs, the rest information is generated, in order to
make sure collision results from test_move, move_and_collide and
move_and_slide are consistent and return a collision in case of overlap.

- The new calculation for recovery vector makes sure the recovery is
never more than the overlap depth between shapes.
This can help with cases where the kinematic body overlaps with several
shapes.
Recovery is made iteratively, without forcing a full overlap at each
step. This helps with getting proper rest information when recovery
occurs.

- One Way Collision:
When attempting motion, contact direction is checked against motion
before skipping in order to solve cases where kinematic bodies can sink
into one-way collision shapes.
Rest info now sets max contact depth in order to properly handle one-way
collision.

- Low speed motion is now handled in the rest info, by never setting
min_allowed_depth lower than motion length.
Separation is always applied with full margin, otherwise contact is lost
when low speed motion occurs right after higher speed motion.

- Similar changes are applied to 3D in order to make 2D and 3D
consistent.
2021-02-17 19:02:59 -07:00
reduz 8b19ffd810 Make Servers truly Thread Safe
-Rendering server now uses a split RID allocate/initialize internally, this allows generating RIDs immediately but initialization to happen later on the proper thread (as rendering APIs generally requiere to call on the right thread).
-RenderingServerWrapMT is no more, multithreading is done in RenderingServerDefault.
-Some functions like texture or mesh creation, when renderer supports it, can register and return immediately (so no waiting for server API to flush, and saving staging and command buffer memory).
-3D physics server changed to be made multithread friendly.
-Added PhysicsServer3DWrapMT to use 3D physics server from multiple threads.
-Disablet Bullet (too much effort to make multithread friendly, this needs to be fixed eventually).
2021-02-10 13:21:46 -03:00
PouleyKetchoupp 50501f2843 Fix physics queries not filtering out disabled collision shapes
This change allows collide_shape, intersect_shape, cast_motion and
rest_info in both 2D and 3D to ignore disabled shapes and make them
consistent with the physics simulation.

In some other cases, _cull_aabb_for_body is used and filters shapes out
internally, but whenever a physics query uses the broadphase directly
without calling _cull_aabb_for_body, disabled shapes can be returned
and need to be filtered out.
2021-02-09 19:14:17 -07:00
Rémi Verschelde d2e1216504
Merge pull request #37547 from aaronfranke/tau
Use Math_TAU and deg2rad/etc in more places and optimize code
2021-02-01 20:55:25 +01:00
Aaron Franke cb9fc117d1
Use real_t in physics code 2021-01-28 18:15:42 -05:00
Rémi Verschelde 011d201046
Merge pull request #43923 from madmiraal/fix-43588
Fix cast_motion sometimes failing
2021-01-14 20:44:19 +01:00
Aaron Franke 1d5042c9e2
Use Math_TAU and deg2rad/rad2deg in more places and optimize code 2021-01-09 03:47:14 -05:00
Marcel Admiraal 7653b8cc1e Fix multiple issues with one-way collisions
For RigidBodies, uses the collision normal determined by relative motion
to determine whether or not a one-way collision has occurred.

For KinematicBodies, performs additional checks to ensure a one-way
collision has occurred, and averages the recovery step over all collision
shapes.

Co-authored-by:    Sergej Gureev <sergej.gureev@relex.fi>
2021-01-07 09:22:39 +00:00
Rémi Verschelde b5334d14f7
Update copyright statements to 2021
Happy new year to the wonderful Godot community!

2020 has been a tough year for most of us personally, but a good year for
Godot development nonetheless with a huge amount of work done towards Godot
4.0 and great improvements backported to the long-lived 3.2 branch.

We've had close to 400 contributors to engine code this year, authoring near
7,000 commit! (And that's only for the `master` branch and for the engine code,
there's a lot more when counting docs, demos and other first-party repos.)

Here's to a great year 2021 for all Godot users 🎆
2021-01-01 20:19:21 +01:00
Marcel Admiraal 356a2b7235 Fix cast_motion sometimes failing
- Fixes Godot physics failing when the cast Shape is inside of, or
already colliding with another Shape.
- Fixes Bullet physics failing when there is no motion.
- Ensures Godot and Bullet physics behave the same.
- Updates the documentation to exclude the caveats for the failures and
differences.
2020-11-27 15:33:00 +00:00
reduz 127458ed17 Reorganized core/ directory, it was too fatty already
-Removed FuncRef, since Callable makes it obsolete
-Removed int_types.h as its obsolete in c++11+
-Changed color names code
2020-11-07 20:17:12 -03:00
Rémi Verschelde c845e20add Revert "Allow Area2D and 3D mouse events without a collision layer"
This reverts commit 7eebb06b55.
2020-07-27 22:45:01 +02:00
Tomasz Chabora 7eebb06b55 Allow Area2D and 3D mouse events without a collision layer
Co-authored-by: madmiraal <madmiraal@users.noreply.github.com>
2020-07-10 13:23:20 +02:00
Marcel Admiraal a442526744 Test collision mask before creating constraint pair in Godot physics broadphase 2D and 3D. 2020-06-08 17:46:21 +01:00
Rémi Verschelde 0ee0fa42e6 Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
2020-05-14 21:57:34 +02:00
Rémi Verschelde 07bc4e2f96 Style: Enforce separation line between function definitions
I couldn't find a tool that enforces it, so I went the manual route:
```
find -name "thirdparty" -prune \
  -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \
  -o -name "*.glsl" > files
perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files)
misc/scripts/fix_style.sh -c
```

This adds a newline after all `}` on the first column, unless they
are followed by `#` (typically `#endif`). This leads to having lots
of places with two lines between function/class definitions, but
clang-format then fixes it as we enforce max one line of separation.

This doesn't fix potential occurrences of function definitions which
are indented (e.g. for a helper class defined in a .cpp), but it's
better than nothing. Also can't be made to run easily on CI/hooks so
we'll have to be careful with new code.

Part of #33027.
2020-05-14 16:54:55 +02:00
Rémi Verschelde 0be6d925dc Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
Which means that reduz' beloved style which we all became used to
will now be changed automatically to remove the first empty line.

This makes us lean closer to 1TBS (the one true brace style) instead
of hybridating it with some Allman-inspired spacing.

There's still the case of braces around single-statement blocks that
needs to be addressed (but clang-format can't help with that, but
clang-tidy may if we agree about it).

Part of #33027.
2020-05-14 16:54:55 +02:00
Rémi Verschelde dcd1151d77 Enforce use of bool literals instead of integers
Using clang-tidy's `modernize-use-bool-literals`.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-bool-literals.html
2020-05-14 13:45:01 +02:00
Rémi Verschelde 69de7ce38c Style: clang-format: Disable AllowShortCaseLabelsOnASingleLine
Part of #33027.
2020-05-10 13:13:54 +02:00
lupoDharkael 95a1400a2a Replace NULL with nullptr 2020-04-02 13:38:00 +02:00