Skip to content

Conversation

@A-Walrus
Copy link
Contributor

@A-Walrus A-Walrus commented Dec 2, 2023

Objective

Fixes: #10832

Solution

If the time is past the final keyframe, just set the transform using final transform

How to test:
Run the animated_fox example and bump the speed up a bunch with up arrow, then hit 1 to run the animation once. On main it won't always stop in the same position, with this PR it always stops on exact value of last keyframe

With main (slightly different results everytime):
Screenshot from 2023-12-02 14-53-14

With this PR:
Screenshot from 2023-12-02 14-54-19

Changelog

Fixed bug where animation wouldn't stop at the value of exactly the last keyframe

Ok(i) => i,
Err(0) => continue, // this curve isn't started yet
Err(n) if n > curve.keyframe_timestamps.len() - 1 => continue, // this curve is finished
Err(n) if n > curve.keyframe_timestamps.len() - 1 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Err(n) is returned when no exact match was found this means that we sample after the last keyframe for n > len - 1. This curve should not contribute to the final pose by default in my opinion. The way most are familiar with this is probably an option "hold". I would continue here and special case it later when this option is implemented.
The rest looks fine

Copy link
Contributor

@VVishion VVishion Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should add curves not contributing anymore is essentially only relevant when blending

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it another thought and my suggestion doesnt result in the last keyframe being applied when we sample with t > curve duration. Im going to give it some more thought for something bullet-proof.

My current stance is that the last keyframe should be sampled when t(i - 1) < curve duration and t(i) > curve duration, but not when t(i - 1) > curve duration and t(i) > curve duration (unless we are holding the animation).
This means we need to keep track of when an animation was last sampled and whether it was sampled the last time the player ran.

Where t(i - 1) is the last time we sampled and t(i) is the time we currently sample.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@A-Walrus A-Walrus marked this pull request as draft December 3, 2023 08:01
@alice-i-cecile alice-i-cecile added A-Animation Make things move and change over time C-Bug An unexpected or incorrect behavior labels Dec 4, 2023
@alice-i-cecile alice-i-cecile added this to the 0.13 milestone Dec 4, 2023
@alice-i-cecile
Copy link
Member

What are your plans with this PR? This is a useful fix: should I put it up for adoption?

@A-Walrus
Copy link
Contributor Author

Yeah put it up for adoption

@alice-i-cecile alice-i-cecile added the S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! label Jan 11, 2024
@alice-i-cecile alice-i-cecile removed this from the 0.13 milestone Jan 24, 2024
@mweatherley
Copy link
Contributor

Closing as outdated/superseded by #15434

@mweatherley mweatherley closed this Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Animation Make things move and change over time C-Bug An unexpected or incorrect behavior S-Adopt-Me The original PR author has no intent to complete this work. Pick me up!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Last keyframe of animation curve not sampled

4 participants