Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RigidBody and RigidBody2D ignore scaling on runtime #5734

Open
Tracked by #45334 ...
akien-mga opened this issue Jul 16, 2016 · 44 comments
Open
Tracked by #45334 ...

RigidBody and RigidBody2D ignore scaling on runtime #5734

akien-mga opened this issue Jul 16, 2016 · 44 comments

Comments

@akien-mga
Copy link
Member

akien-mga commented Jul 16, 2016

Operating system or device - Godot version:
Mageia 6 x64, Godot 2.0.4.1 and master HEAD.

Issue description (what happened, and what was expected):
RigidBody2D does not respect its scale parameter, or that of its parents. When scaling a RigidBody2D (directly or by scaling its parent), it shows properly scaled in the editor, but on runtime the scale is ignored.

Steps to reproduce:

  1. Add a RigidBody2D, with a Sprite to actually see its size
  2. Scale it down or up
  3. Run the project

Link to minimal example project (optional but very welcome):
3.x MRP (works in master too): RigidBody2D_scaling_bug.zip

(Old 2.1 project: RigidBody2D_scaling_bug.zip)

The project has a root Node2D scaled by (0.2, 0.2), and RigidBody2D, StaticBody2D and KinematicBody2D children. When running the scene, you'll see that only the RigidBody2D does not respect its parent's scale.

@akien-mga akien-mga added this to the 2.1 milestone Jul 16, 2016
@reduz
Copy link
Member

reduz commented Jul 17, 2016

This is intended, because physics bodies manage their own transform which overwrites the ones you set.
Some kind of workaround could be done eventually, but not until 3.0

@ivanskodje
Copy link
Contributor

Posting this here in case someone else also needs a "hack" to forcefully make scaling work on RigidBody2D.

You can use integrate forces to set the scale. For example,

func _integrate_forces(state):
	set_scale(Vector2(-1, 1))

@JarLowrey
Copy link

JarLowrey commented May 9, 2017

Also if you set the mode to "Kinematic" it will scale #7375 . _integrate_forces wasn't working for me.

Edit: got _integrate_forces working, think I copied something wrong. That's def better than changing your body type.

@reduz
Copy link
Member

reduz commented Aug 5, 2017

may do a workaround for 3.1 I am still not convinced it will work, though

@raffomania
Copy link

Is there a way to scale rigidbodies before instantiation?

@reduz
Copy link
Member

reduz commented Dec 16, 2017

there should be a tracker with all these things, so i can work and remember everything after 3.0

@aaronfranke
Copy link
Member

@reduz The tracker for items on the 3.1 milestone is https://github.com/godotengine/godot/milestone/7

@reduz
Copy link
Member

reduz commented Jul 29, 2018

Sorry, out of time for 3.1 to create a workaround, kicking again.

@Houkime
Copy link

Houkime commented Dec 9, 2018

Probably it needs to be at least documented in RigidBody2D class description while workaround is in progress?
It took me a little while to decide that it is this issue that is screwing everything up.

@t-karcher
Copy link
Contributor

I fully agree with @Houkime : A hint in the class description would have saved me almost an hour of tearing my hair out trying to figure out what's wrong with my code.

kiku-jw added a commit to kiku-jw/godot that referenced this issue May 16, 2019
* [TileMapEditor] Improve tool picking usability

When KEY_CONTROL is released, go back to the last tool.

Also add a tooltip for paint button with shortcuts for line draw and
rectangle paint.

* Make buttons that trigger popups have the same scale

* Make 'Line/TextEdit's context menus hide their editing options when in readonly mode

Fixes godotengine#28243.

* Renames captions of Scalar/VectorInterp in Visual Shaders

* Warn when opening imported anim in AnimationPlayer

* C#: Support resource type hint in exported arrays

- Elements of types like PackedScene will display with the special editor for such type.

* Fixed GLES2 transparency order

* Added an is_valid function to FuncRef so script can check if it is safe to call it.

* issue-28446 - disable higlighting all occurences of string in editor if only whitespaces are selected

* Set range for line spacing

* Fixed a few issues with the bezier animation track editor, fixed the Travis CI errors, added TTR to bezier value labels and rounded them to 3 decimal points

* Add and expose to Font a function to get the rect size needed to draw a word-wraped text

* Fix build error after godotengine#27294

* SCons: Always use env.Prepend for CPPPATH

Include paths are processed from left to right, so we use Prepend to
ensure that paths to bundled thirdparty files will have precedence over
system paths (e.g. `/usr/include` should have lowest priority).

* Properly expose PhysicsServer methods

* Forgot a parameter in the ARVR gdnative bindings for notifications

* Fix sign-compare error from godotengine#26051

* doc: Sync classref with current source

* GridMap editor fixes and improvements

This change fixes a few outstanding issues and greatly improves the usability
of the GridMap editor through the following changes:

- Copied mesh now gets displayed during pasting (also renamed the related
  identifiers accordingly)
- Duplication/paste indicator now gets rotated around the correct pivot point
  (duplication worked properly before, but the indicator was shown misplaced
  when rotated)
- Selected mesh library item cursor is no longer shown during selection and
  duplication/pasting
- Back rotate X/Y/Z is now working during duplication/pasting
- Added true cut operation thanks to now having a proper clipboard (clear
  operation got remapped to the DEL key)
- Got rid of some weird workarounds in the duplication code
- Fill and clear operations now correctly make the selection marker inactive
  as this was broken partly due to the workarounds mentioned above
  (duplication continues to keep the selection marker active to allow
  subsequent duplications)
- Clear current selection on RMB, but treat selection as an action so previous
  selection can be restored on undo
- Separated selection and paste indicator data as it's prone to error and
  confusion and it's anyway needed now that selection is treated as an action
- Added support for cancelling paste, selection, and even unselect the
  currently selected mesh library item with the ESC key (previously there
  wasn't a way to unselect)
- Changed the key binding of fill/clear/duplicate operations to use Ctrl as a
  modifier
- Changed erase to use RMB instead of Shift+RMB (free look is available
  through Shift+F anyway, so no need to occupy RMB for it during gridmap
  editing)
- Removed unused area, external connector, and configure menu items (there's
  also the non-functional clip mode menu items, but I'm not sure whether there
  are any plans with that, I suppose it's meant to be an editor aid)
- Renamed INPUT_COPY to INPUT_PICK to better reflect its purpose
- Added support for using Shift+Q and Shift+E to select multiple floors/planes
  without actually changing the current floor/plane as it happens when using
  e.g. the mouse wheel

Fixes godotengine#25373 and godotengine#15883

* Fix script dialog path validation to handle spaces correctly

* fixes bug when setting projection matrix

* Make "decimal" functions more consistent

In GDScript, rename "decimals" to "step_decimals". In C#, add "StepDecimals", but keep the old functionality in a method called "DecimalCount".

* Fix missing argument for vsnprintf_s

* fixes 27543, adds a copy button for the editor log

* Fix regression on 'PopupMenu's minimal size

* Fixed game crash, regression of godotengine#26977

Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com>

* Small documentation improvements

* Fix pvrtc encoder
Always resize image to square of power2
Enable mipmaps only if original texture has it enabled
Fix godotengine#28534, godotengine#28541

* Support Mac OS default move cursor hotkeys

Add missing FALLTHROUGH define

* Fix Remove Missing Project projects on Windows

* Revert "Update libwebsockets to 3.1 (plus UWP patch)"

This reverts commit 90210c4.

* Added missed inputs for other modes in visual shaders

* Change order of Visual Script Search.

Previously:

* vs nodes
* properties
* methods

Now:

* properties
* methods
* vs nodes

* VS: Better ux

* In VS functions' put the current node type first.
* Cleanup and merge property and method sections.

* VS: Give the generic search the current base type.

* Freetype clone env for no-SMID single file

Fix freetype build issue for javascript platform.
When disabling optimizations (SMID) in specific freetype, source files,
we need to make sure to copy all other CPPFLAGS, not just override them.

* Fix First Ctrl+R and Ctrl+F not showing long name variables correctly

* Add a property hint for DynamicFont size

This caps its size to reasonable values in the Inspector.

This closes godotengine#22581.

* Fix input entries when switching to new visual shader

* Locales: Add some missing locale names

* Ignore a warning in _get_socket_error (-Wlogical-op).

drivers/unix/net_socket_posix.cpp: In member function 'NetSocketPosix::NetError NetSocketPosix::_get_socket_error()':
drivers/unix/net_socket_posix.cpp:197:22: warning: logical 'or' of equal expressions [-Wlogical-op]
  197 |  if (errno == EAGAIN || errno == EWOULDBLOCK)
      |                      ^

and:

modules/mono/utils/string_utils.cpp: In function 'int {anonymous}::sfind(const String&, int)':
modules/mono/utils/string_utils.cpp:68:48: error: logical 'or' of collectively exhaustive tests is always true [-Werror=logical-op]
      found = src[read_pos] == 's' || (c >= '0' || c <= '4');
                                       ~~~~~~~~~^~~~~~~~~~~

* Fix typed arrays and dictionaries getting their values shared

* Document CollisionObject2D pickable requires collision_layer

Documents CollisionObject2D mouse_entered, mouse_exited and input_event requiring at least one collision_layer to be set.

* Fix slight issues with autocompletion and member lists in GDScript

Fixes godotengine#27152
Fixes godotengine#28591

* Fix regression in 'PopupMenu' when icons have different values for width and height

* Fix script dialog asking for correct inheritance when not needed

* Make small changes to the script dialog

* Add "disabled" icon for 'CheckButton'

* Hide "Built-in Script" option in the script creation dialog when not possible

* Fix Mac OS move cursor behaviour

* added MSAA to GLES backend

* Make "Find in Files" always available in the script editor

* Fix build visual_shader_editor_plugin

* Remove unused `panelf` and `panelnc` styles

Fixes godotengine/godot-docs#2426

* Fix collapse visual shader tree

* Fix navmesh not finding optimal paths

Addresses part of godotengine#17885

* Update of RigidBody2D class description

Added a hint in the RigidBody2D class description regarding the transformation issue mentioned in godotengine#5734

* Make 'TabContainer' update when icon/title is changed

Fixes godotengine#28655.

* Fixes VideostreamGDNative crash on audio_channel=0.

Added an if case to check if the mix_callback exists before running any
of the audio code.

Fixes: godotengine#28644

* Support Mac OS default delete char hotkeys

* Document dictionary erase return value

* Fix ParallaxBackground breaking when moving it out the scene tree

* fix CollisonShape changing shape cause crash when not in a tree

* Fix generation of Mono Glue for Visual Studio 2017+

vsnprintf definition should only be changed when MSC version is older than 2013. The version check and fix is taken from StringUtils.h of assimp.

* Fix 'TabContainer' not updating its tab titles when locale is changed

* Make editor close empty scene when creating an inherited one

Fixes godotengine#28654.

* Update AUTHORS and DONORS list

New contributors added to AUTHORS:
@Kanabenki, @KoBeWi

Thanks to all contributors and donors for making Godot possible!

* Remove reduz from some autorequested code reviews

He's still one of the main architects of some of these code branches,
but quite often PRs that modify one or two files in such folders don't
necessarily need his input, and he has enough backlog to handle.

PR triagers will ask for his review manually whenever relevant. He's
left as code owner for physics/visual servers and rendering backends.

* Center shape according to logic Bullet applies

* Add transform support to deal with Bullets centering of shapes

* Fix SHADOWS_DISABLED flag in GLES2

Signed-off-by: Guilherme Souza <gdsdsilva@inf.ufpel.edu.br>

* Improved the AnimatedSprite docs; added description to speed_scale.

* Revert "Merge pull request godotengine#28715 from YeldhamDev/inherent_scene_close_empty"

This reverts commit 0f8356d, reversing
changes made to 7b7a664.

* Change empty scene closing on new inherented scene to a better approach

* Fix texture resource reload bug

If a non-imported texture resource file (e.g. DDS) gets updated the editor
doesn't reload it. The cause of the problem is two-fold:

First, the code of ImageTexture assumes that textures are always imported
from an image, but that's not the case for e.g. DDS. This change thus adds
code to issue a resource reload in case an image reload is not possible
(which is the case for non-imported texture resources).

Second, the code is filled with bogus calls to Image::get_image_data_size()
to determine the mipmap offset when that should be done using
Image::get_image_mipmap_offset(). Previous code literally passed the integer
mip level value to Image::get_image_data_size() where that actually expects
a boolean. Thus this part of the change might actually solve some other
issues as well.

To be pedantic, the texture_get_data() funciton of the rasterizer drivers is
still quite a mess, as it only ever returns the whole mipchain when
GLES_OVER_GL is set (practically only on desktop builds) but this change does
not attempt to resolve that.

* Docs: Add tutorials for KinematicBody2D

* Revert "Merge pull request godotengine#26053 from qarmin/back_scroll_to_start"

This reverts commit b5deb1d, reversing
changes made to 2cc8848.

This change causes unwanted regression.
It's too risky to have scroll back to top in ItemList.clear()

* Scroll back to top when changing directory in FileSystem dock

Fix godotengine#26041

* [EditorSpatialGizmo] Fix error in intersect_ray

* Avoid _can_call_mode resetting error message in MultiplayerAPI

* Change "ID" to lowercase "id"

Reasoning: ID is not an acronym, it is simply short for identification, so it logically should not be capitalized. But even if it was an acronym, other acronyms in Godot are not capitalized, like p_rid, p_ip, and p_json.

* Fix AudioEffectRecord messing up the effect stack by not writing to dst_frames

* X11: Check if "_NET_FRAME_EXTENTS" atom is supported.

* Fixes to ClippedCamera

This work has been kindly sponsored by IMVU.

* Allow or_greater for most properties of NavMesh

Closes godotengine#28624

* Open selected folder when pressing the "Open" option in the menu

An attempt to fix godotengine#28798

* Add RegEx substitution testcase and fix relevant docs

(cherry picked from commit a31bbb4)

* Make possible to create inherited scenes via the RMB menu in the FileSystem dock

* Fix orientation of generated navmeshes

Fixes godotengine#23817

* Apply sprite frames editor FPS value correctly upon _animation_select

* updated description of Array.shuffle to properly describe that it uses the same common seed at every runtime, thus being reproducible in general

* AnimatedSprite: Add from spritesheets now work as expected. Fix godotengine#28030

* Better handle some self-RSET/RPC in MultiplayerAPI

Allow calling yourself via RPC/RSET if the mode allows it.
Better error messages when you are not allowed to call yourself.

* Fix GDNative library resource loading.

Store general properties in ConfigFile too when modifying them.
Additionally set config_file property as internal as it's not editable
from inspector. It also does not appear to get saved in a meaningful way
(saved as Object(ConfigFile, ...))

* added radiance when using clear color and fixed brdf

* Properly update script button when undoing a script addition

Fixes godotengine#28870.

* Improve the CanvasItem documentation

This makes it clear that line width and antialiasing in
`draw_multiline()` aren't implemented yet (see godotengine#16448).

* Make Xcode recursive search frameworks in project dir

* fix lighting bug introduced in clear color changes

* Fix NaN with get_action_strength

* doc: Sync classref with current source

* doc: Fix issues found by the parser

* Update GDNativeLibrarySingletonEditor.

Moved GDNative singletons discoverer from register_types to
GDNativeSingletonEditor.
Fix enable/disable switch in GDNativeLibrarySingletonEditor.
Separate `gdnative/singletons` and `gdnative/singletons_disabled`
project settings, keeping "on by default" behavior.

* Fix OS_Javascript execute method

Signature was changed in OS via:

cd4449e

* Fix indexing failure in NativeScriptLanguage::unregister_binding_functions.

binding_functions.size() and an instance's binding_data.size() can get out of sync. They sync up when an instance's bindings are requested. When binding functions are registered after creating an instance's bindings, the instance's bindings are out of sync until requested again. If they're never requested, they're never synced.

unregister_binding_functions indexes into binding_data, but only checks that its safe to index into binding_functions. When they're out of sync, indexing fails.

This revision checks that it's safe to index into binding_data.

* Fix OS_UWP::execute's signature after cd4449e

Same as godotengine#28919.

* Revert "Revert "Implemented terrain raycast acceleration""
akien-mga pushed a commit to akien-mga/godot that referenced this issue Jul 3, 2019
Added a hint in the RigidBody2D class description regarding the transformation issue mentioned in godotengine#5734

(cherry picked from commit 1170b78)
@Calinou
Copy link
Member

Calinou commented Mar 1, 2022

apparently this problem still exists in 3d in version 4a3?? is this on the to do list??

pouleyKetchoupp is no longer available to work on the physics engine, so I can't guarantee this limitation will be lifted for 4.0. We have very few contributors who are knowledgeable with physics and have time to submit contributions to the existing physics engine implementations.

@Okxa
Copy link

Okxa commented Mar 15, 2022

One update on this issue; it seems that on godot 3.4.2-stable the uniform scaling (like I posted on this thread earlier) works when using bullet, but not on godot physics.

(That came up when I tried to switch to godot physics for #29392 / #34596, because #56801 has not been merged.)

@hmans
Copy link

hmans commented Nov 22, 2022

Just a quick ping to find out if anything has happened in the meantime. In 4.0, apparently Bullet is no longer available, only GodotPhysics3D. Scaling a scene that contains a RigidBody3D (and probably also its 2D equivalent) still yields warnings & scaling resets at scene start.

I understand this is an Open Source project and I could just take the source and fix this myself, but this is outside of my abilities. I also understand that features are usually added/fixed by people who need them, so please don't misunderstand my comment here as me demanding anything. I just can't imagine that I'm the only person on the planet who'd like to take a scene prefab and spawn smaller and larger versions of it?

(As a reminder, I am very specifically not looking for being able to change the scale at runtime; just at spawn time. And uniform scale only would be perfectly fine.)

@akien-mga
Copy link
Member Author

@hmans You can work it around fairly easily by changing the size of the collision shape, instead of scaling the RigidBody.

Here's a quick example in 2D:
image

You'd scale the parent node, whose script takes care of setting the size of the collision shape and propagating the scale to the sprite. The RigidBody itself is not scaled and works fine.

@hmans
Copy link

hmans commented Nov 22, 2022

Thanks @akien-mga, but in that example the RigidBody node will now simulate (and move) independently from its parent node, correct? So this isn't of much use as a reusable prefab scene.

I remember adding code to a Rigidbody node (the last time I actually tried building a physics game with Godot :b) that would apply the Rigidbody's scale to its children like you're doing, and then reset the Rigidbody's own scale back to 1/1/1.

Also consider that this can be a little more complex than just the children's scale. Colliders might be offset (with their origin not at 0/0/0); this would also need to be scaled accordingly.

(It would be immensely useful here if colliders didn't need to be parented directly to their rigidbodies. Then we could have an intermediate node between the two and just scale that one.)

I'm hoping for a future version where hacks like these are no longer required.

  • It's trivial in Unity
  • It's trivial in Unreal
  • It should be trivial in Godot

(Don't get me wrong, I fully understand that these engines also just rescale collision radii/polygons/etc. — I'm just making an argument for Godot abstracting this away so you can have a small ball and a large ball from the same prefab and not go hunting for hacks like the one above.)

I'll check again next year :-)

@hmans
Copy link

hmans commented Feb 11, 2023

Woohoo:

Screen.Recording.2023-02-11.at.13.37.53.mov

As a workaround for this issue, I've created a new class called ScalingRigidBody3D in Godot 4.0 (feedback welcome):

@tool
class_name ScalingRigidBody3D
extends RigidBody3D

var _size := 1.0

@export var size : float:
	get: return _size

	set(v):
		_size = v
		_apply_size()

func _ready():
	_apply_size()

func _apply_size():
	for child in get_children():
		if child is CollisionShape3D:
			child.scale.x = size
			child.scale.y = size
			child.scale.z = size

This can probably be improved further.

My personal wish for Godot's (3D) physics would be to

  • have the built-in RigidBody3D class apply a similar logic, but out of the box (for example, it could, in _ready(), examine its world scale, set its own scale back to 1/1/1, and scale its children accordingly. Doing this in _ready() should be enough since scaling works fine during the editing experience.)
  • remove the editor warning that appear when you scale rigidbodies

Baby steps, but we'll get there :)

Update!

Improved version of the above class — doesn't use a new property, but just applies its own scale to its children as described in the notes above:

class_name ScalingRigidBody3D
extends RigidBody3D

func _ready():
	_apply_scale()

func _apply_scale():
	# apply my own scale to my children
	for child in get_children():
		if child is Node3D:
			child.scale *= scale

	# reset my own scale
	scale = Vector3.ONE
  • Probably has a bunch of edge cases. Most importantly, it assumes that there's no parent node applying additional scaling (but this could probably be fixed trivially.)
  • The editor experience is fine (you can scale rigidbody nodes and see the results), but you'll still get the annoying warning triangle. I wish there was an editor option to disable them. But more than that, I wish for this type of logic to eventually end up living in the RigidBody3D class itself. ;)

Update 2023-03-07:

I've polished the code, gave it some upgrades, and packaged it into a Godot Plugin. Please see this comment for details.

@koekhaos
Copy link

@hmans New to Godot and going through the tutorials wanted to try to make the 2d balls smaller and found this issue. Would your script work somehow for 2d too if just changing a few calls inside and changing to vector2? Thanks!

@hmans
Copy link

hmans commented Feb 23, 2023

@hmans New to Godot and going through the tutorials wanted to try to make the 2d balls smaller and found this issue. Would your script work somehow for 2d too if just changing a few calls inside and changing to vector2? Thanks!

Yup, that should work!

If there's interest, I could wrap this into a plugin and publish it in the Asset Library (but probably for 4.0+ only.)

@koekhaos
Copy link

koekhaos commented Feb 23, 2023

That could be super useful as a lot of people seem to want this but doesn't seem to be in the works anytime soon as it looks like the milestone is set to 4.1 now to fix/implement.

@hmans
Copy link

hmans commented Mar 7, 2023

Hi and good morning to everyone following this issue! I've packaged my glue code into a Godot 4.0 Plugin that you can add to your project to work around this issue:

Godot RigidBody Auto Scaler 🎉

It's "fire and forget"; just add it to your project and it'll fix things up automatically. I've also given it a couple of upgrades: it now respects parent scale, also fixes child positions, and works for both 2D and 3D.

While the Asset Library listing submission is still pending, you can find it here:

https://github.com/hmans/Godot-RigidBody-Auto-Scaler

Feedback welcome! (But preferably outside of this issue thread. The plugin README is listing a bunch of ways you can get in touch with me!)

@Okxa
Copy link

Okxa commented Mar 8, 2023

Another problematic thing when scaling rigidbodies with the workaround (eg. RigidBody is at scale 1 and CollisionShape & mesh are at your desired scale) is that automatically calculated inertia does not seem to scale.

If you use PhysicsServer3D.body_get_direct_state(get_rid()).inverse_inertia.inverse() to check inertia, it is the same regardless of the child objects scale. This makes objects fall somewhat weirdly looking.

If I set the scale manually to something like calculated_inertia * scale it looks slightly better. (For example if calculated inertia is about (15000,7000,15000) on each xyz axis, and scale is 0.2, it's about (3000,1400,3000) respectively)

(However if I set the RigidBody3D mass to 1000, and the inertia in the editor for each axis, the model flies downwards through the floor, as if it had massive gravity. If I only set to x & z axis, it does not go through floor. When using the above function to check inertia, it reports the value set in editor for the x/z axis, and for z axis it's the autocalculated value.)

EDIT: As a workaround, it is possible to scale the inertia with script (at runtime), where ever you just have access to PhysicsDirectBodyState3D, like _integrate_forces() (or by getting it with PhysicsServer3D.body_get_direct_state(get_node(".").get_rid())). Using _integrate_forces() or _physics_process() is usefull as inverse_inertia is not set (inf) at _start():

var has_set_inertia = false

func _integrate_forces(state):
    if !has_set_inertia:
        var inertia_actual = state.inverse_inertia.inverse()
        if !is_inf(inertia_actual.x):
            # get scale from child collider node, assuming you have already applied scale with the workaround
            self.inertia = inertia_actual * collider.scale
            has_set_inertia = true

@hmans
Copy link

hmans commented Mar 8, 2023

Another problematic thing when scaling rigidbodies with the workaround (eg. RigidBody is at scale 1 and CollisionShape & mesh are at your desired scale) is that automatically calculated inertia does not seem to scale.

If you use PhysicsServer3D.body_get_direct_state(get_rid()).inverse_inertia.inverse() to check inertia, it is the same regardless of the child objects scale. This makes objects fall somewhat weirdly looking.

Good point! I'll look into this. Thanks!

@Okxa
Copy link

Okxa commented Oct 8, 2023

Update: Using Godot Jolt physics engine, rigidbody scaling gets slightly better. (Godot Jolt is consired as physics engine, see: godotengine/godot-proposals#7308)

  • Rigidbody children still need to be scaled instead of rigidbody itself (ie with hmans addon)
  • It seems Rigidbody inertia is automatically calculated! for example:
var has_print_inertia = false
func _integrate_forces(state):
    if !has_print_inertia && self.inertia == Vector3.ZERO:
        var inertia_actual = state.inverse_inertia.inverse()
        if !is_inf(inertia_actual.x):
            print(name, inertia_actual)
            has_print_inertia = true

outputs:

prop_physics10(0.031431, 0.031431, 0.003251)
prop_physics11(0.031437, 0.031437, 0.003251)

image

The prop_physics are sized the same, but with this difference:

  • prop_physics10 has a CollisionShape scaled to 2 (with a ConvexPolygonShape3D exported from blender after scaling to 0.01 -> apply scale)
  • prop_physics11 has the same shape, but exported without applying scale (== 100x bigger when imported to godot), and then scaled in godot to 0.02

Also tested with godot physics and expectedly above function printed different inertia for the rigidbodies.

@jitspoe
Copy link
Contributor

jitspoe commented Jul 7, 2024

Just wanted to add to this, as I think it's the same/similar issue: It seems the rigid bodies will attempt to invert the scaling when re-parented to something of a different scale.

When I was working on the Godot plushy for KOOK, I wanted to have the arms and legs flop around, so I had joints and rigid bodies for them. When I pick rigid bodies up, they would get reparented to a bone on the player. The first person player is actually much smaller than everything else to avoid clipping through walls, so the objects picked up got scaled down (and there's an additional scale factor as well, just to fudge things so they look right, like 0.8x). The pinned rigid bodies, which are a child of the plushie would actually get scaled UP when everything else got scaled down, so they'd be sitting at > 1.0. When I dropped the object and changed the parent back to the world, they'd still be scaled larger (possibly because it was a non-uniform scale, as stuff in first person is actually squished as well).

Here's a clip from the dev stream where this happened. The white cube is a mesh that's a child of the RigidBody3D, for visual feedback: https://clips.twitch.tv/InspiringFrozenDotterelUWot-XoUI1ECrtU8-isdX

@hmans
Copy link

hmans commented Jul 10, 2024

Just wanted to add that current GodotJolt stable seems to support this out of the box. It even seems to support non-uniform scaling. That's pretty cool!

Godot 4.2 is still giving me the little exclamation mark warning that I'm doing something that I'm not supposed to be doing, but it looks like it can be safely ignored.

@Okxa
Copy link

Okxa commented Jul 14, 2024

Just wanted to add that current GodotJolt stable seems to support this out of the box. It even seems to support non-uniform scaling. That's pretty cool!

Can confirm, here is a clip using Godot 4.2.2 and godot-jolt stable release 0.12. Each RigidBody is scaled just by their transform. IIRC this was not working on 0.11 (which was version I previously used), but not sure.

2024-07-14.10-41-56.mp4

The inertia also seems to be still scaled correctly, as was when using previous godot jolt version.

Checkroth added a commit to campenr/radius-game that referenced this issue Aug 18, 2024
Adds a workaround that manually scales the children of the Projectile
scene.
This is due to a problem where the projectile root node scale does not
propagate down to the sprite or collision shape within it.

godotengine/godot#5734
Checkroth added a commit to campenr/radius-game that referenced this issue Aug 19, 2024
Adds a workaround that manually scales the children of the Projectile
scene.
This is due to a problem where the projectile root node scale does not
propagate down to the sprite or collision shape within it.

godotengine/godot#5734
Checkroth added a commit to campenr/radius-game that referenced this issue Aug 19, 2024
Adds a workaround that manually scales the children of the Projectile
scene.
This is due to a problem where the projectile root node scale does not
propagate down to the sprite or collision shape within it.

godotengine/godot#5734
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests