Skip to content

Fixed start time when normalized time is not zero#1

Merged
vanifatovvlad merged 1 commit into
codewriter-packages:masterfrom
faveris:master
Aug 12, 2022
Merged

Fixed start time when normalized time is not zero#1
vanifatovvlad merged 1 commit into
codewriter-packages:masterfrom
faveris:master

Conversation

@faveris
Copy link
Copy Markdown
Contributor

@faveris faveris commented Aug 12, 2022

In our game we have a character and a weapon as separate meshes. We use MeshAnimation for character and simple legacy animation for weapon. It works fine, but when start time is not equal to zero, animations go out of sync:

bug.mov

Example code for reproduction:

// Mesh animation
_meshAnimator.Play(clipName, 1.5f, 0.3f);

// Legacy animation
AnimationState state = _animation[clipName];
state.speed = 1.5f;
state.normalizedTime = 0.3f;
_animation.Play(clipName);

I found two issues which lead to this bug in MeshAnimationAssetExtensions.Play method, when calculating start time:

  1. We should decrease start time but not increase, because it should be considered that animation is kind of started in the past when normalized time is greater than zero.
  2. We have to take into account that speed could be not equal to 1, therefore data.lengthSeconds should be devided by speed (or better use already calculated s)

Result after a fix:

bugfix.mov

@vanifatovvlad vanifatovvlad merged commit ed22c76 into codewriter-packages:master Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants