godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.11k stars 69 forks source link

Rigidbody2D Bone/Joint #2597

Open Virusthe opened 3 years ago

Virusthe commented 3 years ago

Some of my examples logic and how I think this could be implmented might be wrong but I will need to check again

Describe the project you are working on

A 2d fully physics-based combat game with joints.

Describe the problem or limitation you are having in your project

I can't get physics-based joints to work.

Describe the feature / enhancement and how it helps to overcome the problem or limitation**

A new physics/rigid joint2D node that will allow for things such as physics-based animations, or even a softbody2d type node. Another way of implementing this would be to extend the rigid body to add "connections"

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams**

Description: This node is similar to the nodes that inherit joint2D is used for bone style rotation specifically for connecting two rigid bodies or rigid body and static body Implantation summery -the "underling" body rotation point is the "master" body's position. Drawing-1 sketchpad light blue circle = central "master" rigid body (see Properties List for more info)

  1. person with sword and shield
  2. robot shooter thing
  3. general grievous quad-wielding lightsabers
  4. A dude with those tentacle things from Tokyo ghoul or doctor octo guy from spiderman
  5. EPIC dragon
  6. dude with crab claws Example of how a character could work(specifically the first sword dude): Rotational/Linear forces can be added to the "main body part" Forces are then distributed among the other part (this is explained more later). Animations can be made and stored (see later example). -(project specfic) Damage is dealt with based on the velocity of the object * the attack of the object. Each object also has health which gets destroyed after it loses all its health. Properties List (master/underling node placement matters) -"master" node (this body will have the center used for rotation?) -"underling" node -rotation weight (force distribution) range 0 to 1 (one is basically just a solid "bone" with no rotation) -rotation limits _____ (useful for physics-based animations and is used with the animation player. The animation player is used to set joints at a proper rotation) -rotate to point/range = bool (on/off thing) -rotation to point/range (moves the joint to this range) -rotation force (the amount of force used to move joint to this range)

Examples of this Drawing-5 sketchpad (3) The green boxes are collision shapes and in this situation the connected rigidbodys should stay togetter at the same lenght/"share mass"

Rotation weight Drawing-2 sketchpad (1) the force is applied with a collision. body 2 = master body 1 = underling 100F is added to body 2 for ex. 1-3, 4 has 100F added to body 1

  1. has a weight of 0 - all 100F gets distributed to the rotation of body 1
  2. has a weight of 0.5 (but I probably got the vectors wrong) - 50F gets added to body 1's rotation, 50F is distributed to body 2's rotation/linear velocity (the force applied to the master body is effectively apply_impulse(collision position,Vector2(0,-50))
  3. has a weight of 1 0F is added to body 1, 100F is distributed to body 2's rotation/linear velocity
  4. regardless of the weight 4 will always the same - 100F is added to body 1 which moves both bodies Multi-linked bodies examples Drawing-5 sketchpad Description of body: -all blue circles are rigid bodies -the light blue circle rigid body acts as the body you would do your movement with like a joystick or your preferred input type -the connection goes from the light blue circle rigid body as the master and shoulder connections as underlings -the filled in light blue circle this the main rigid body. -the two shoulder connections have a weight of 1 meaning you could apply an unlimited amount of force and the shoulder parts will never rotate The arm values and applying force examples are what I'm interested for now Drawing-5 sketchpad (1) For the following examples, I'm simplifying the body even more (because I'm not a computer and using my imagination for these force calculations is hurting my brain =( ) this secton is done yet Rotation limits (min rot value, max rot value) Any forces added to the underlying body gets converted to linear velocity/rotation for the master body if the vector pushes up aganist the limits __This section should be used with the animation player and the rotation is applied to the master body in each body link -rotate to point/range = bool (on/off thing) (just to turn this option on/off) -rotation to point/range (moves the joint to this range) -rotate force (the amount of force used to move joint to this range) Simple example Drawing-4 sketchpad -each stance can be saved in an animation player and then you can switch between each one for movement -animations are made with joint rotations/rotational force for the movement -when the body is within the rotation range/point the rigidbody just stops rotating entirely unless moved out of the range

    If this enhancement will not be used often, can it be worked around with a few lines of script?

    No

Is there a reason why this should be core and not an add-on in the asset library? I think this will be useful for users doing 2d physics

Extra thing -I think this could also be used to make a softbody2d node too if one were to add some sprite deformations -Basically, with this node, you would draw a polygon2d/shape2d and using the "soft points property" you can set the number of rigid body points and with the hardness property 0 - 1 you can get the hardness of the object. The soft body "pushes" the same way a "body moves" with animation player thing" -points which are rigid bodies should be distributed equally among the lines of the shape -properties -polygon2D/shape2D -hardness 0 to 1 - (0 would make the body drop into a pile of lines - 1 would make the body unbendable) -soft points -edit individual points -mass (this gets divided equally by default among all the points unless a point is edited by the edit individual points thing. Example (no image yet)

jeffrey-cochran commented 3 years ago

This is usually called "articulated rigid body" dynamics in my experience. Maybe include that in the title for folks who recognize the term.

As a sidenote, I'm working on a 2D SoftBody implementation right now. I won't create a proposal for it until after it's finished and tested, though.

jeffrey-cochran commented 3 years ago

@Virusthe if you ever want to try implementing articulated rigid bodies yourself, this book has an excellent treatment of the topic, and all the details of its implementation: https://www.cs.clemson.edu/savage/pba/

That said, I can't remember if they describe it on terms of a PID control, step-and-project, or direct enforcement. I've actually implemented this before, and I'll post a picture later

jeffrey-cochran commented 3 years ago

@Virusthe see if this proposal accomplishes what you want:

https://github.com/godotengine/godot/pull/47872