+1 vote

Hi,

I'm still working on my 2D ragdoll :).
(Gifs in my previous topic)

There are 2 relevant nodes:
1.) player: this is a kinematic body
2.) corpse: this contains rigid bodies which are connected with pin joints

The corpse node is not in the scene tree until the player dies.

The structure:

player (KinematicBody2D):

- Camera2D (current = on)
- AnimationPlayer
- CollisionShape2D
- Sprite_1 (head image)
- Sprite_2 (neck image)
- Sprite_3 (chest image)
(etc.)

corpse (Node2D):

- Camera2D (current = on)
- RigidBody2D_1 (head)
---- CollisionPolygon2D
---- Sprite (head image)
- RigidBody2D_2 (neck)
---- CollisionPolygon2D
---- Sprite (neck image)
- RigidBody2D_3 (chest)
---- CollisionPolygon2D
---- Sprite (chest image)
(etc.)

- PinJoint2D_1 (head-neck)
- PinJoint2D_2 (neck-chest)
(etc.)

My plan is when the player dies, I replace it's node with the corpse, like this:

remove_child(player);
add_child(corpse);

( Sub-question: am I on the right way? :D )

After this I want to initialize the corpse (according to the player's last values): position, direction (left-right), rotation of the arms/legs... etc.

My problem is that I can not change the corpse node's direction (left-right).
In the kinematic body I use the set_scale() function for this purpose (with positive/negative X depending on the direction), but I just realised that the rigid bodies are ignoring these values at runtime :(.

How can I do this (without duplication of the corpse node... if possible)?

Thank you!

in Engine by (674 points)
edited by

What if you use a rigid body (or bodies) on kinematic mode and when dies changes to rigid?

Good idea, thank you!
Yes, the scaling works in kinematic mode, but it is reset immediately when I change the mode back to rigid :/

if the shapes are symmetric, you can scale/flip the sprites only.

The shapes are asymmetric, and the sprites are not in the center of the main ("corpse") node :(
Looks like this:
enter image description here

1 Answer

+1 vote
Best answer

It is by design that rigid bodies don't scale. There was talk of adding a warning.

The rotation should be fine for some cases.

Here is a more complete explanation:

https://github.com/godotengine/godot/issues/2129

For scaling you can alter the physics shapes and child sprites directly via script, but that can sometimes turn into a mess with certain node layouts.

by (5,247 points)
selected by

OK, rigid bodies are not scalable (design concept), I accept this.
Thank you!

I have to reorganize my nodes, and write this method (horizontal flip) for myself.

I will scale the sprites and the collision polygons directly (not the rigid body), then I calculate their X coordinates... actually it looks easy :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.