HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] how to rotate bone via script / animation  (Read 5185 times)

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
[Resolved] how to rotate bone via script / animation
« on: Jul 05, 12, 12:44:06 PM »

Hi!

I am trying to rotate a bone in my character procedurally. Can someone give me a hint on how to do it?
So far, i made a rather naive animation squence that looks like this:
!
! Animation Sequence Spec
! template Sequence generated by Max or Maya output
Version=1
[ABILITIES]
 Rotate Bone
   .BoneName=bonerudder
   .StartRotation=(0,40,0)
   .ApplyToMotionVector=false
   .ScaleController=1


But it didn't really work... all i get is the following error:

19:32:29: !ERROR!System:AnimationSequence [animrudderleft] has invalid InitialDuration (0.000000)

What i am trying to achieve is that the bone rotates to the certain angle when i press the key on keyboard, and goes back to a starting rotation when i unpress the key. If i can make this happen via a clever combination of an 3ds max animation/asq/aas i would appreciate hints on that too!

Cheers!

« Last Edit: Oct 26, 12, 12:48:15 PM by HE-Cooper »
Logged

HE-Cooper

  • *****
  • Posts: 2221
    • View Profile
Re: how to rotate bone via script / animation
« Reply #1 on: Jul 05, 12, 12:50:16 PM »

If you look at the FPS reference, we are using bone rotation to aim up and down, I think. We were using animation blending at first, but pretty sure we ended on bone rotation. The bone has a knob with a value, and the script updates that knob value based on the where the mouse moves up and down.

So the robot has a full body set of animation like run, etc. Then has an upper body mask for holding the gun, or the axe, etc. And we rotate one of the spine bones up or down via script.
Logged

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how to rotate bone via script / animation
« Reply #2 on: Jul 05, 12, 02:02:21 PM »

Hmm, if i'm not mistaken, this is a part that handles it? FPS_ACCCcontroller client class.
The problem is, how do i check the asq with AimAmount knob?
Seems to me that when i open the repository browser i have limited visibility options (is says that "some files are not shown"). I belive this is a dynamic character named FPS_Hero, right?

function FPS_SetBoneRotation()
  cam2 as NodeRef = GetActiveCamera()
  rot as Vector3 = GetNodeRotation(cam2)
  if rot.y < 0
    knob_value as Float = rot.x/85
    SetAnimFloatKnob(SYSTEM.INFO.PLAYERCHARACTER,"AimAmount",knob_value)
    return
  .
  if rot.y > 0
    knob_value as Float = rot.x/85 * -1
    SetAnimFloatKnob(SYSTEM.INFO.PLAYERCHARACTER,"AimAmount",knob_value)
    return
  .
.

Logged

HE-Cooper

  • *****
  • Posts: 2221
    • View Profile
Re: how to rotate bone via script / animation
« Reply #3 on: Jul 05, 12, 09:04:24 PM »

Yeah, repository security is on to prevent folks from mucking with things. I've attached a zip with all the animation related files.
Logged

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how to rotate bone via script / animation
« Reply #4 on: Jul 06, 12, 12:55:11 AM »

Hi!

Thanks for the files!

From what i see in these animation sequences, the bone rotation is done with an "additive blend"?
I might go that road as well, although somewhere i read that  they are compute-intensive compared to bone rotation.

I need to get my hands dirtier with this, get my brain wrapped around what these attributes below mean, and then i'll get back to you.


Version=1
[ABILITIES]
  Add
    .SequenceA=fps_sniper_idle
    .SequenceB=fps_aim_up_90
    .ReferenceAnimation=fps_idle.hgm
    .BlendController=AimAmount
    .BlendAmount=
    .Preload=True



It would be most helpful if you could explain what kind of an animation is fps_idle, and what kind of animations hide behind fps_sniper_idle and fps_aim_up_90 animation sequences.
« Last Edit: Jul 06, 12, 11:38:27 AM by AWW_boss »
Logged

HE-BENNETT

  • HeroEngine
  • *****
  • Posts: 559
    • View Profile
Re: how to rotate bone via script / animation
« Reply #5 on: Jul 09, 12, 08:04:25 AM »

The FPS robot is actually still using blended animation sequences to achieve to the aiming up and down.  Depending on what you're trying to do this may or may not be the best approach.  (and regardless of engine, additive animations are difficult to create, much less setup properly)

If you could describe what you're trying to do, I can give you my opinion on which approach would probably be better.  From your first post, it sounds like you're just animating a rudder on a boat?  For something like that, you almost certainly would want to use a rotate bone sequence.

Additive is more useful for something like an fps, where I can add the same aim up/down animations to any of several gun specific 'aim_idle' poses.

I'll take a look at the rotate bone sequences and see if I can figure out your issue.

*edit: wrong 'your' x.x
« Last Edit: Jul 09, 12, 09:01:07 AM by HE-BENNETT »
Logged

HE-BENNETT

  • HeroEngine
  • *****
  • Posts: 559
    • View Profile
Re: how to rotate bone via script / animation
« Reply #6 on: Jul 09, 12, 09:09:24 AM »

Hmmm, I am seeing the same error on a simple test case created from the wiki instructiongs, AWW_boss.  We'll take a closer look at this ASAP, as there does seem to be some issue.  Hopefully it's as simple as the documentation on the wiki not being updated to include info on specifying duration.  :)
Logged

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how to rotate bone via script / animation
« Reply #7 on: Jul 09, 12, 09:22:05 AM »

Hi!

You were correct, but it's a airplane rudder, not a boat rudder  :) . The behaviour should be simple:

1. pressing a key should start rotating it towards maximum angle
2. when it reaches the maximum angle it holds
3. unpressing a key leaves it at a current angle (or rotates it back to the 0 angle - i haven't yet decided on the implementation)

I have already setup an animation channel for the rudder, and i have everything setup in my controller.
I am interested in how should my animation sequence look like.


Thanks for help
« Last Edit: Jul 09, 12, 09:24:29 AM by AWW_boss »
Logged

HE-BENNETT

  • HeroEngine
  • *****
  • Posts: 559
    • View Profile
Re: how to rotate bone via script / animation
« Reply #8 on: Jul 09, 12, 10:28:38 AM »

Got it.  The 'duration' is being sampled from the animation that should be playing on the character.  Basically, you can't have an ASQ file that only contains the rotate bone ability.  It must also contain an apply animation ability.  Here's an example from HJ:


!
! Animation Sequence Spec: combat_walk
! 03/05/2009 20:17
!
Version=1
FallbackSequence=walk_male
[ABILITIES]
  Apply Animation
    .Animation=combat_walk
    .InitialSpeed=1
    .InitialLoop=True
    .InitialAlign=False
    .Preload=True
  Rotate Bone
    .BoneName=Bip01 Neck1
    .StartRotation=(25,0,0)
    .EndRotation=
    .LoopCount=0
    .Duration=0
    .ApplyToMotionVector=False
    .ScaleController=BodyTwistKnob
  Rotate Bone
    .BoneName=Bip01 Spine1
    .StartRotation=(20,0,0)
    .EndRotation=
    .LoopCount=0
    .Duration=0
    .ApplyToMotionVector=False
    .ScaleController=BodyTwistKnob
  Rotate Bone
    .BoneName=Bip01 Spine2
    .StartRotation=(20,0,0)
    .EndRotation=
    .LoopCount=0
    .Duration=0
    .ApplyToMotionVector=False
    .ScaleController=BodyTwistKnob


Note that the ".Duration=0" attribute does nothing, as that was never implemented. 
Logged

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how to rotate bone via script / animation
« Reply #9 on: Jul 09, 12, 12:44:27 PM »

Meh, i still cannot make it happen. I don't understand what kind of animation should i have in apply animation ability, nor the meaning of .StartRotation and  .ScaleController attributes. Rereading wiki didnt help either, the enlightement just wont come.

I tried rotating the bone with an animation which doesn't do anything, and different values of .StartRotation and .ScaleController attributes but nothing happens :(


like in the example below:

!
! Animation Sequence Spec
! template Sequence generated by Max or Maya output
Version=1
[ABILITIES]
 Apply Animation
    .Animation=animnone.hgm
    .InitialSpeed=1
    .InitialLoop=true
    .InitialAlign=false
    .VDA=false
  Rotate Bone
    .BoneName=Bip01
    .StartRotation=(0,90,0)
    .EndRotation=
    .LoopCount=0
    .Duration=0
    .ApplyToMotionVector=False
    .ScaleController=0.5
Logged

HE-BENNETT

  • HeroEngine
  • *****
  • Posts: 559
    • View Profile
Re: how to rotate bone via script / animation
« Reply #10 on: Jul 09, 12, 12:55:06 PM »

First off, don't worry about EndRotation, LoopCount, or Duration, they do nothing.


.StartRotation is actually the rotation that you are applying. (x,y,z) in degrees, I believe. 

.ScaleController is how you will interface with the rotate Bone ability from script.  It needs to be the name of an fKnob that you create in script, such as 'BodyTwistKnob' or something like that.  You need to specify that name as the value  of .ScaleController (.ScaleController=BodyTwistKnob) in the sequence file and ALSO need to create that knob in a script when you want to set its value.

The number that you set .ScaleController to is a factor to multiply the .StartRotation amount by before adding it to the bone's rotation.  So, if you set BodyTwistKnob's value to 1 and .StartRotation=(0,90,0), the bone would rotate 90 degrees around its y axis.

The animation you'd be running in this case would just be a still idle, since a rudder doesn't do a whole lot.  Make sure you have at least a few frames, though in theory a single frame animation should work.

I'm actually having a little trouble myself getting a test case functioning, so don't beat your head against a wall.  It may be that something has changed, as there were some bugs associated with the Rotate Bone ability that were recently fixed.  I'm still looking into it and I'll let you know what we come up with :)
Logged

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how to rotate bone via script / animation
« Reply #11 on: Jul 09, 12, 01:06:12 PM »

Aha!

So in my case, since i put it to 0.5, the result would be a 45 degrees rotation  (90 * 0.5) around its y axis.
OK, im waiting for your input.
Thanks.
Logged

HE-BENNETT

  • HeroEngine
  • *****
  • Posts: 559
    • View Profile
Re: how to rotate bone via script / animation
« Reply #12 on: Jul 09, 12, 01:11:59 PM »

Well, almost.  I don't believe you can directly specify a numeric value in the sequence file, such as .5

You have to specify the name of a fknob, which you later create and modify the value of through heroscript.  By putting a number there, HeroEngine is probably now expecting you to create an fknob called ".5", which probably isn't a valid name.

these pages should help you with the fknob stuff:

http://wiki.heroengine.com/wiki/Asq#Knobs
http://wiki.heroengine.com/wiki/Animation_functions#GetAnimKnobs
Logged

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: how to rotate bone via script / animation
« Reply #13 on: Jul 09, 12, 02:11:29 PM »

I got it working! Thank you so  much.
The fknob hint did it.
Logged

HE-BENNETT

  • HeroEngine
  • *****
  • Posts: 559
    • View Profile
Re: how to rotate bone via script / animation
« Reply #14 on: Jul 09, 12, 03:37:49 PM »

Glad to hear it :)
Logged