godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add 2D root motion in AnimationTree #5303

Open mhoff12358 opened 2 years ago

mhoff12358 commented 2 years ago

Describe the project you are working on

A 2D game where the player fights enemies whose attacks (and their properties like hit boxes) are defined by animations

Describe the problem or limitation you are having in your project

The lack of root motion for 2d transforms means that playing a new animation resets the Node2D's position rather than letting it aggregate.

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

In addition to being able to select a 3D Position track as the source of root motion, also allow value tracks that are Node2D position values to be selected. Then any animation changes to that track won't actually be applied to the Node2D directly, and will instead be exposed through the root_motion property of the AnimationTree. Users can then apply this offset through their own scripting, either directly or through a CharacterBody2D's move_and_slide method.

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

The basic functionality for this already exists for 3d root motion. This will replicate that code but for 2D transforms instead. https://github.com/godotengine/godot/pull/65183 shows this working for 2D positions.

One issue is that in 3D it's more obvious how to have the user select the position AND rotation AND scale. For 2D the best idea I have is to have them select the position track and then also implicitly look for the nearby rotation and scale tracks.

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

No, this cannot be easily worked around with scripting. It would require a lot of wrapping around animation playback and might not work in all edge cases.

Is there a reason why this should be core and not an add-on in the asset library?

It is a feature added to the existing AnimationTree node, changing existing method behavior. So adding it through a plugin would require recreating core functionality.

smedelyan commented 1 year ago

I'll just leave this one here in case it may help anyone to workaround while the feature is not yet there: https://godotengine.org/qa/42831/root-motion-in-2d. At least in my simple case it worked out well enough

AccumPlus commented 1 year ago

The feature is very desirable! šŸ‘

Calinou commented 1 year ago

@AccumPlus Please don't bump issues without contributing significant new information. Use the :+1: reaction button on the first post instead.

MotasemZakarneh commented 3 months ago

on #1191 someone suggested the following:

You can use a parent-child node structure to effectively get relative transforms https://github.com/godotengine/godot-proposals/issues/1191#issuecomment-658106154 and you can read my expereince/response in here https://github.com/godotengine/godot-proposals/issues/1191#issuecomment-2294808679

i added a detailed description in there, on why, that may not be such a good idea of a solution, but in case someone wants to go through that whole process they may go ahead, and read the details of potential problems that you may face. Granted as i mentioned in my comment in #1191 i believe its possible, but it'll probably be around 1500 lines of code to go through and fix all of these edge cases, and depending on your game, you may face even more, which is not feasible, which leads me to make this comment in here.


as i said in the other ticket about relative frames #1191 i think the core, and true focus, should be root motion in 2D because of the following reasons:

  1. its already implemented for 3D, so should be relatively straightforward to hard code, by just duplicating a lot of the code from the 3D, while its dirty and is duplicated code, but it does the job (personally for me, if a code piece is duplicated more than 3 times then it becomes a problem, and while that may not align with godot standards, but given that this is an issue that blocks developers making animation heavy 2D games from transferring to godot, i think it may be worth, especially considering there is no proper solution in sight, which is relative key frames).
  2. The core issue boils down, not to relative key frames, but to the fact that, we do not have root motion/root rotation, root scale, in 2D, i think if we have that, then it will essentially cover most use cases, and while having relative key frames is a great feature to have, being unable to use it for things like color for example wouldn't really be that much of a problem to me (as someone in a team making an animation heavy 2D game), but lack of root motion/rotation in 2D, makes it unfeasible to me.

With that said, i am a bit new to the godot source code world so i could be saying a lot of non sense that does not fit to godot world and sorry if that is the case.

but i would love to hear what more expereinced developers think about whether it would be fine to just hard code a solution for 2D similar to what was done for 3D and if not, what prevents such thing from happening?

smedelyan commented 3 months ago

@MotasemZakarneh I can see there are methods like get_root_motion_position() in AnimationMixer (and, consequently, AnimationPlayer & AnimationTree). You can also specify root_motion_track, so maybe the feature is there already, only the related issues not closed?

MotasemZakarneh commented 3 months ago

now, i could be just stupid, and have missed something essential, but in godot 4.3

image

i simply can not seem to select any root motion track šŸ˜“ in this setup of a scene obviously, i tried removing the node3d parent, and keeping a node 2d one, or whatever, but neither really works, i could not specify/select anything in the inspector. (even dragging and dropping did not work).