Jump to content

Animation Question


Daemoc
 Share

Go to solution Solved by Yue,

Recommended Posts

I looked around for this information, but had no luck finding it.

In the script animation calls, there are 3 values at the end of the string. Through trial and error I think I figured most of it out, although it does not make much sense.

The first value seems to be playback speed. The question I have is how does this calculate? I have an animation set to 30 frames a second in the model, but in engine I have to set it to a value of 0.02 to look right? What is the equation here?

The second number, I am guessing is the frame count? Shouldn't this be set by the animation though?

I have even seen a third value on a few strings, but I have not figured out what this does, or if it is even required.

Sorry for the stupid questions, but this does not seem to be documented anywhere.

Link to comment
Share on other sites

  • Solution

https://www.leadwerks.com/learn?page=API-Reference_Object_Entity_PlayAnimation

The first value refers to the name of the animation or its respective number in sequence. 

The second value is the speed, this doesn't really agree with my modeling program, and I think it's especially due to the keyframes marked in the animation so it's time to look for a calculation that matches the engine.

In the third value, is the speed with which you change between animations, a default value is 500, but I use 100 milliseconds, which implies that the transition between animations is smooth.

A fourth value, is by default the number zero, this implies that the animation is reproduced in a cycle where when arriving to the last keyframe it returns to the first one, if the value of the number 1 is put to the animation they are reproduced in a single shot, it is not a cycle and it is then when we can resort to the script in Script EndAnimation(), where the number of that sequence is returned when that animation finishes.

 

 

 

 

Link to comment
Share on other sites

Below is a simple example if you want to write your own system.

void characterclass::animate()
{
	double lastanimframe = animframe; 
	animframe += timesincelastframe * animationspeedvariable;

  
	//  While animation frame is over the total length of the animation, reduce it  
  	//  so we always stay between 0 and the animation length - 1
	while(animframe > (double)model->GetAnimationLength(animstate)-1)
		animframe -= (double)model->GetAnimationLength(animstate)-1;
  
  
 	//  You can see if animation hit a specific frame to check for a sword hit on an enemy or whatever action you'd like
 	//  The below line checks if we're animating an attack and we hit or passed frame 10
	if(animsate=="attack" && animframe >=10 && lastanimframe<10)
	{
		//  Do action here
	} 

  
	//  When animation ends...
	if(animframe > (double)model->GetAnimationLength(animstate)-1)
	{
		//  You can change your animation state to whatever you'd like
		//  For example, if a sword finished swinging, you can switch back to an idle animation
	}


	model->SetAnimationFrame(animframe, 0.7, animstate, true);
}

 

Link to comment
Share on other sites

I just use the old animation lua script Josh had because I built this idea into it and working with callbacks in Lua is just easier. Still wish by default this LE PlayAnimation function gave us that capability, or he added a RegisterAnimationEvent() function to link the timing to a function.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...