Advertisement

Applying rotation from animation

Started by December 23, 2023 12:08 AM
0 comments, last by snoken 1 year ago

Hi,

I am having a weird issue when rotating my character with animation. The issue is that a position in the world is being interpreted differently depending on the direction of the character. When I do not apply the animation rotation data to it, it seems correctly identify the position -519.0f, 0.0f, 1210.0f but when I do apply the animation rotation data, this same position is understood to be somewhere else when the characters forward direction begins facing the opposite way In this diagram, the pink arrow denotes the forward direction of the character. the Red flag is where the position -519.0f, 0.0f, 1210.0f should be and it is where the player ends up with no animation rotation applied.

Image

The white flag is where the player ends up when applying animation rotation and im not sure why this is happening

if(joint->joint_name == "RootBone")
{
	offset_from_parent.x = playerpos.x + blendedTranslation.x;
	offset_from_parent.z = playerpos.z + blendedTranslation.z;

	if(AnimState == TurnLeft || AnimState == TurnRight)
	{
		if(!transitionToAnim.empty())
		{
			// get the latest animation to transition to in the queue
			auto transitionAnim = transitionToAnim[transitionToAnim.size() - 1];
			// check if this is the final frame of the animation 
			if((transitionAnim.frame_count - 1) == ((frame + 1) % transitionAnim.frame_count))
			{
				auto animRot = transitionAnim.SampleAnim((frame + 1) % transitionAnim.frame_count, jointID);
				
				Quaternion a_rotY = Quaternion(animRot.y, vec3(0.0f, 1.0f, 0.0f)); 
	
				playerpos = vec3(0,0,0);
				playerdir.Rotate(animRot.y, vec3(0.0f, 1.0f, 0.0f));
				playerdir = dir.unit();	
				playerpos = offset_from_parent.toVec3();
				
			}
		}
	}
	
}
It turns correctly for the first few frames the turn animation cycle is running but after around 3 cycles in, it become choppy

This topic is closed to new replies.

Advertisement