rotationQuaternion and Animation

Greets everyone,

I am making progress in my Aiming-Targeting-System, but got some troubles with:

  1. using BABYLON.Quaternion.RotationAxis. Does it expect bone axis (I use TransformNode of bone) or global world axis?
  2. How do I trigger a function on finish of two “unlooped” animations (rotation)?

My PG: https://playground.babylonjs.com/#3ZJLP2#58

Info: I can’t use lookAt because I have to calculate rotation of aiming, where I need roationQuaternion.toEulerAngles() so I can limit the rotation to min-max.

About 1. BABYLON.Quaternion.RotationAxis does not expect anything per se :slight_smile: Basically here as you animate rotationQuaternion of smthg, you are animating the local value which would then be impacted by the parent ones.

About 2. You would need some kind of flags to know that both animations are done or a counter that you would update in the animationEndCallback.

1 Like

I tried the onAnimationEnd-function but it seems to call the function before the animation is done:

Could you simplify your code to something focusing only on the animationEnd callback ?

I can not repro anywhere else so I suspect the issue is in your current playground logic but it is quite large to go through all of it in debug only.

I removed the whole shooting (bullet) part and simplified to only rotate animate towards target, what i recognized is that there were several animations being created, so i used mesh.animations.length = 0, to remove animations before new is inserted, but it did no help. So it seems my animation logic is not correct?

Here is the PG:

Edit: What is unclear to me is, does RotationAxis “rotates by”- or “rotates to”-angle? Because I need “rotate to”. Regarding this there is my addition of rotationQuaternion to aimRotation, which is directly related to this, also the AnimationLoopMode.

I thought it through again, is there a way to only use an animation once and not pushing to animations-array of mesh/transformNode, which seems to be for repetitive animations?

Also I found AnimationGroup to use

for (anim of animatableE.getAnimations()) {
       this.animationGroup.addTargetedAnimation(anim.animation, anim.target);
 }
this.animationGroup.onAnimationEndObservable.add(() => {
     this.ready = true;
});

But I dont get it to work. Maybe it is a better way and you are able to implement it?

Edit2: Another idea i had was to not use animations, instead I just rotate by absoluteQuaternion and localEulers, so I am able to use my parameters, but that does not rotate correctly, see my new PG:

Edit3: After hard work i solved it using LookRotation of Unity and then Quaternion.Slerp.