• Runtimes
  • [Unity] Play animation in specified angle

I have got following problem. I have harpoon gun:

There is one shoot animation. The default angle for shooting is 0, but I would like to shoot in any other direction +/-30 degrees etc. I am rotating cannon:

harpoongunSkeleton.skeleton.FindBone("bone").rotation = Mathf.Sin(time * 3) * 3*(4 - time) + aimAngle;

but when i play animation it shoots with default (0 degrees) direction.

I could not find anything on forum, but I suppose it is simple problem, and I do not know search terms.

Thanks for help.

Related Discussions
...
  • Изменено

In Spine, you need to open the firing animation, and remove the key that's setting the rotation of the canon.

Your other option is to perform your rotation with SkeletonAnimation's UpdateLocal event, like this:

void Start () {
     harpoongunSkeleton = GetComponent<SkeletonAnimation>();
     var cannonBone = harpoongunSkeleton.skeleton.FindBone("bone");

 harpoongunSkeleton.UpdateLocal += delegate {
      // whatever calculations for time and aimAngle
      cannonBone.rotation = Mathf.Sin(time * 3) * 3*(4 - time) + aimAngle;
 };
}

Why is time a part of the angle computation though?

месяц спустя

Thanks, works like a charm!

Time is a part of angle computation, because enemy is aiming - changing cannon rotation (up and down). Magnitude is decreasing. When cannon is aimed at desired angle, it fires.