Blend 2 animations

Posted By: 3run

Blend 2 animations - 06/26/12 03:43

I've found out that in first half-life there are only two animations for making player aim up and down, so at the end, they just blend between them and that makes character aim at the center. I tried to do something like that myself as well, but I failed by getting some weird results grin Here are the screens of the positions:
Quote:
aim up:

aim down:
So what I want now, is to blend between those animations, and make character aim straight forward.
I used to blend between three animations, when my model had additional "aim_center" animations..
But I need to do this without a third animation, I wonder maybe someone has an idea.
Here is the code I try to use currently:
Code:
function blend_test(){
	// aim at the center:
	my.skill5 = 50;
	// main loop:
	while(1){
		// rest animations:
		ent_animate(my, NULL, 0, 0); 
		// go throw the animations:
		my.skill2 += time_step * 2;
		// blend between animations via Q and E keys:
		my.skill5 += key_q - key_e;   
		my.skill5 = clamp(my.skill5, 0, 100); 
		// if skill5 is less than 50 % then we aim up:
		if(((50 - my.skill5) * 2) > 0){
			my.skill3 = (50 - my.skill5) * 2;  
		}   
		// if skill5 is more than 50 % then we aim down:
		if(((50 - my.skill5) * 2) < 0){
			my.skill4 = abs((50 - my.skill5) * 2); 
		} 
		// blend animations:
		ent_blendframe(my, my, "aim_up", my.skill2, my.skill3);
		ent_blendframe(my, my, "aim_down", my.skill2, my.skill4);
		wait(1);
	}
}


Posted By: Helghast

Re: Blend 2 animations - 06/26/12 07:58

been a while, but if I recall correctly, you need to reset the bones before you can blend them, so blending between 3 animations is gonna be difficult tongue

However, I'm wondering why you dont just use 1 animation (aim forward) and rotate the spine by code to make him aim anywhere?
Posted By: the_clown

Re: Blend 2 animations - 06/26/12 08:32

For that you better use ent_blendpose. It allows to blend between any number of animation poses. So what you do is simply setting the entities pose parameter to 2, animate the "aim up" part of it, then set the pose parameter to 3, animate the "aim down", then do a ent_blendpose of pose 2 and 3 by 50 percent and finally copy the pose into pose 1 to make it visible.
Something like this:

Code:
function entityAim(ENTITY* ent, var percent)
{
        my = ent;
	
	my.pose = 2;
	ent_animate(my,"aimUp",100,ANM_CYCLE);
	
	my.pose = 3;
	ent_animate(my,"aimDown",100,ANM_CYCLE);
	
	ent_blendpose(my,2,3,percent);
	ent_blendpose(my,1,2,100);
	

}



Now, if you call this function with a percent value of 50, you should have the straight aiming, if you call it with a percent value of zero you should have aiming up, and with a percent value of 100 aiming down. Any values between these will result in interpolations.
However, this is just typed out of nothing, not sure if it works flawlessly. And of course you still have to calculate the percent from somewhere else, and if you wanna have additive animations (to do this while the entity is standing, running, walking, whatever) you'd have to add that. However, this is the rough idea how it could work.

EDIT: oh, and this only works with bones as far as I recall, however I guess you're using bones anyways.
Posted By: 3run

Re: Blend 2 animations - 06/26/12 10:46

Helghast@ I don't use it, simply cause I don't have such model grin And I'm not able to animate it myself as well. BTW, it's not that really hard to blend between three animations, from 1 to 2 and from 2 into 3 (up, center, down) laugh

the_clown@ I got the same result already, with the script above (only one "ent_animate" line is missing).
Result isn't really good.. It doesn't look as it should grin And yes, I'm using bone animations.

Here is the screen for you guys to see:

Still, I have no idea why thins happens, cause in half-life game, this works perfect.. Any other ideas?
And thank you for your time guys.

Edit: here is, how should it looks like:

Posted By: Locoweed

Re: Blend 2 animations - 06/26/12 19:53

Don't think what you are doing on will work. It will blend down to Aim Down or up to Aim Up, but will never end up at Aim Center like you are trying to achieve. You can blend from Aim Up or Aim Down to Aim Center animation though.

Loco
Posted By: 3run

Re: Blend 2 animations - 06/26/12 19:54

Hey Locoweed, I see your point. But how to blend into Aim Center? Poke me in the right direction pls :>
Posted By: HeelX

Re: Blend 2 animations - 06/26/12 20:11

As the manual says about end_blendpose:

Quote:
Blending by linear interpolation computes intermediate vertex positions rather than intermediate bones angles. Thus it produces the best results when the bones angles of source and target pose are not too different, like less than 90 degrees


So, blending by frames is done in the end by interpolation the positions of the vertices rather than rotating actually the bones. That is the reason why your image looks weird. --- Maybe Valve implemented a complex blending by interpolation the bone positions/angles via quaternions and recalculation of the vertices.

Nevertheless, you should add more frames inbetween - Gamestudio can't provide IK so it would always look strange, imho.
Posted By: 3run

Re: Blend 2 animations - 06/26/12 20:15

Originally Posted By: HeelX
Maybe Valve implemented a complex blending by interpolation the bone positions/angles via quaternions and recalculation of the vertices.
I hope you are wrong and GS could handle such stuff frown
Do you mean "aim_center" by "more frames inbetween"??

Thank you all for your time guys, I really appreciate it!
Posted By: HeelX

Re: Blend 2 animations - 06/26/12 21:09

Bones animation just stores the skeleton and the associated vertices and the frames. This way, you save lots of memory and you can do independent stuff with bones. Vertex recalculation on intermediate, blended bone poses was never not supported.
Posted By: 3run

Re: Blend 2 animations - 06/27/12 09:31

So this isn't possible with gs?
Posted By: painkiller

Re: Blend 2 animations - 06/27/12 10:07

why not using an anim center animation and use ent_bonerotate to aim up and down?
Posted By: 3run

Re: Blend 2 animations - 06/27/12 10:38

OMG, I've already said that my model doesn't have "aim_center" animation and I'm not able to do that myself!
Posted By: HeelX

Re: Blend 2 animations - 06/27/12 10:38

I would make an animation, in which your character moves his arms from above to the bottom with 6/12 or 24 frames per second, get the 50% pose and voilá.
Posted By: 3run

Re: Blend 2 animations - 06/27/12 14:01

I wanted to handle all this stuff via script only.
© 2024 lite-C Forums