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

Incremental root motion rotation will produce a wrong locomotion #93821

Closed
RickyYCheng opened this issue Jul 1, 2024 · 1 comment · Fixed by #93855
Closed

Incremental root motion rotation will produce a wrong locomotion #93821

RickyYCheng opened this issue Jul 1, 2024 · 1 comment · Fixed by #93855

Comments

@RickyYCheng
Copy link

RickyYCheng commented Jul 1, 2024

Tested versions

Godot v4.2.2.stable.mono - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Laptop GPU (NVIDIA; 31.0.15.2698) - AMD Ryzen 7 5800U with Radeon Graphics (16 Threads)

System information

Godot v4.2.2.stable.mono - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Laptop GPU (NVIDIA; 31.0.15.2698) - AMD Ryzen 7 5800U with Radeon Graphics (16 Threads)

Issue description

I was tesing a root motion animation with rotation and translation.
Following the godot documentation, I use animation tree to get root motion and code is listed here.

func _physics_process(delta): # or _process(delta):
	if incremental_rotation:
		set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation())
	else:
		quaternion = animation_tree.get_root_motion_rotation_accumulator()
	var velocity: Vector3 = (animation_tree.get_root_motion_rotation_accumulator().inverse() * get_quaternion()) * animation_tree.get_root_motion_position() / delta
	set_velocity(velocity)
	move_and_slide()

Toggle the incremental_rotation bool variable will switch the behaviours of the application of root motion.
If it is false, we will just set the absolute rotation data and otherwise, we will set rotation step by step (apply rotation frame by frame).

This animation drives the character to move along z axis and rotate with y axis. (Root bone was set correctly, tip-up)
The absolute root motion mode will reproduce this behaviour, but when using incremental mode, the (x, y) value of character will increase in the same time.


image

correct one

image

wrong one

Steps to reproduce

See MRP.

Minimal reproduction project (MRP)

root_motion_test.zip


Additionally, this code will produce a correcy locomotion but a wrong rotation while using increment mode

# use this.quaternion in velocity instead of animation_tree.get_root_motion_rotation()
func _physics_process(delta):
	if incremental_rotation:
		set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation())
	else:
		quaternion = animation_tree.get_root_motion_rotation_accumulator()
	var velocity: Vector3 = (quaternion.inverse() * get_quaternion()) * animation_tree.get_root_motion_position() / delta
        # Oops! (quaternion.inverse() * get_quaternion()) means Quaternion.Identity
	set_velocity(velocity)
	move_and_slide()
@RickyYCheng
Copy link
Author

RickyYCheng commented Jul 1, 2024

And I found a documentation mistake. Please check: get_root_motion_rotation_accumulator
This line:

var current_root_motion_rotation_accumulator: Quaternion = animation_tree.get_root_motion_Quaternion_accumulator()

get_root_motion_Quaternion_accumulator should be get_root_motion_rotation_accumulator.


And this line:

transform.basis *= difference

The interpreter of gdscript just tell us that can not multiply a Basis variable with a Quaternion variable. So the proper solution would be

transform.basis *= Basis(difference)

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

Successfully merging a pull request may close this issue.

3 participants