Commit graph

193 commits

Author SHA1 Message Date
PouleyKetchoupp
bfd0d33244 Fix errors in CharacterBody when floor is destroyed or removed
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-10 08:27:33 -07:00
Camille Mohr-Daurat
c6062cd93e
Merge pull request #54134 from nekomatata/body-center-of-mass-local
Expose local center of mass in physics servers
2021-11-08 18:44:51 -07:00
PouleyKetchoupp
fc8c766ef9 Expose local center of mass in physics servers
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-08 16:17:57 -07:00
Rémi Verschelde
e87687a6d0
Merge pull request #54486 from ibrahn/thread-work-pool-lazier 2021-11-08 13:39:39 +01:00
Brian Semrau
dc11e73bf0 Rename AABB get_area to get_volume 2021-11-05 18:22:42 -04:00
Camille Mohr-Daurat
70c82d9d3d
Merge pull request #54642 from BoilingFusion/master
Fix the volume calculation for cylinders
2021-11-05 15:08:57 -07:00
Julian Adamse
03903fdeec Fix the volume calculation for cylinders 2021-11-05 20:49:14 +01:00
PouleyKetchoupp
acbd24ea84 Use parameter classes instead of arguments for all physics queries
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-04 11:44:39 -07:00
rafallus
770e3a8e51 Use Callable in Area monitor callback 2021-11-01 21:53:17 -06:00
Ibrahn Sahir
151d2e34ca ThreadWorkPool no longer starts worker threads if given zero work. 2021-11-01 19:19:25 +00:00
Camille Mohr-Daurat
a57de3b818
Merge pull request #37880 from nekomatata/rigid-body-damping-override
Improved RigidDynamicBody linear/angular damping override
2021-11-01 11:24:01 -07:00
Rémi Verschelde
3a6be64c12
clang-format: Various fixes to comments alignment from clang-format 13
All reviewed manually and occasionally rewritten to avoid bad auto formatting.
2021-10-28 15:43:36 +02:00
Rémi Verschelde
3b11e33a09
clang-format: Disable alignment of operands, too unreliable
Sets `AlignOperands` to `DontAlign`.

`clang-format` developers seem to mostly care about space-based indentation and
every other version of clang-format breaks the bad mismatch of tabs and spaces
that it seems to use for operand alignment. So it's better without, so that it
respects our two-tabs `ContinuationIndentWidth`.
2021-10-28 15:19:35 +02:00
PouleyKetchoupp
daf7dcac7a Improved RigidDynamicBody linear/angular damping override
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-25 18:22:12 -07:00
reduz
d03b7fbe09 Refactored Node3D rotation modes
* Made the Basis euler orders indexed via enum.
* Node3D has a new rotation_order property to choose Euler rotation order.
* Node3D has also a rotation_mode property to choose between Euler, Quaternion and Basis

Exposing these modes as well as the order makes Godot a lot friendlier for animators, which can choose the best way to interpolate rotations.
The new *Basis* mode makes the (exposed) transform property obsolete, so it was removed (can still be accessed by code of course).
2021-10-25 14:34:00 -03:00
PouleyKetchoupp
d804c34285 Fix RigidDynamicBody collision update after changing collision layer/mask
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-21 17:36:58 -07:00
PouleyKetchoupp
e6f7235ffb Fix SoftDynamicBody3D crash when setting disable mode
Proper logic for changing physics state when disabled and disabled mode
is changed (it was unnecessarily making calls to re-initialize physics).

Extra error handling in soft body implementations to avoid crashes with
invalid mesh.
2021-10-21 08:56:12 -07:00
PouleyKetchoupp
c1577e5a3f Fix 2D center of mass not updated from transform
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-19 16:22:30 -07:00
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
mennomax
b4eeeb315a
Swap args of Plane(point, normal) constructor
Now (normal, point)
2021-10-15 20:49:42 -05:00
Rémi Verschelde
6637207c70
Merge pull request #53420 from nekomatata/fix-tilemap-moving-platform 2021-10-05 10:50:56 +02:00
Camille Mohr-Daurat
4778770d3c
Merge pull request #53365 from danger-dan/wakeup_fix
Use wakeup() function to wake sleeping bodies on impulse, force and velocities. Fix for PR #52967
2021-10-04 18:03:35 -07:00
Daniel
243f235300 Changed from directly waking bodies to using the wakeup() functions in direct body state changes (forces, impulses and veloicities). this 'bug' was introduced in PR #52967
added wakeup to 2d direct body
2021-10-05 13:17:05 +13: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
Rémi Verschelde
5b270278c8
Merge pull request #53280 from nekomatata/test-body-motion-parameters 2021-10-04 21:05:38 +02: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
f9702cc8d0 Fix crashes with pinned vertices in GodotPhysics Soft Body 2021-10-04 08:45:27 -07:00
Haoyu Qiu
f3816898fa Fix crash when pinned SoftBody point is out of range 2021-10-04 16:42:53 +08:00
PouleyKetchoupp
b8eeb34b4e Remove scene code in physics servers
Replaced Mesh with mesh RID in Godot Physics 3D and Bullet.
2021-10-01 08:42:47 -07:00
Lightning_A
c63b18507d Use range iterators for Map 2021-09-30 15:09:12 -06: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
Haoyu Qiu
9dd0d3f550 Don't memcpy to nullptr even if length is zero 2021-09-29 20:58:14 +08:00
Camille Mohr-Daurat
341b532d5e
Merge pull request #52754 from nekomatata/dynamic-body-modes
Clarify RigidDynamicBody modes
2021-09-28 17:11:17 -07:00
Rémi Verschelde
60988a06c2
Merge pull request #52953 from nekomatata/fix-collision-recovery-depth 2021-09-28 12:11:38 +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
Daniel
e8efe621d5 Added set_active(true) to all body direct state force apply/impulses. #52915 2021-09-24 17:22:51 +12: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
Anilforextra
90908cd67d Add Get Center Method for Rect2/Rect2i and AABB. 2021-09-21 21:14:17 +05:45
Aaron Franke
bf0213470c
Replace Vector3.to_diagonal_matrix with Basis.from_scale 2021-09-17 10:30:30 -05:00
PouleyKetchoupp
ed1ba5093f Clarify RigidDynamicBody modes
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-16 16:03:48 -07:00
Camille Mohr-Daurat
062cff373a
Merge pull request #52668 from qarmin/cppcheck_servers_physics
Initialize variables in servers/physics
2021-09-16 09:06:03 -07:00
Camille Mohr-Daurat
1852afb6b0
Merge pull request #52679 from nekomatata/world-boundary-shape
Rename WorldMarginShape to WorldBoundaryShape
2021-09-15 16:02:40 -07:00
qarmin
91257c3900 Initialize variables in servers/physics 2021-09-15 19:41:32 +02:00
PouleyKetchoupp
bb75aec8bc Rename WorldMarginShape to WorldBoundaryShape 2021-09-14 11:16:31 -07:00
Aaron Franke
3a902c66c4
Revert some URLs from the "Replace HTTP URLs with HTTPS" PR 2021-09-13 15:18:35 -05:00
PouleyKetchoupp
8d56354f7c Optimize raycast with large Heightmap shape data
Port raycast accelerator from Bullet's btHeightfieldTerrainShape.
2021-09-06 16:01:44 -07: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
Camille Mohr-Daurat
e1ae2708ee
Merge pull request #52271 from nekomatata/query-layer-default-mask
Harmonize default value for collision mask in ray/shape queries
2021-09-06 09:33:18 -07:00
PouleyKetchoupp
83baecdff0 Add AnimatableBody inherited from StaticBody for moving platforms
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-31 18:14:32 -07:00