Problem with Ani.Mate

Currently trying to use Ani.Mate to perform a translation and rotation at the same time but I’m getting the error: “InvalidCastException: cannot cast from source type to destination type”

Can anyone shed any further light on this, as I’m really not sure whats wrong with my code as it’s pretty much copy pasted from the AniMate wiki page!

My code (javascript):

yield Ani.Mate.To(this.transform, 0.5, {“position”: new Vector3(sledX,2.5,sledZ), “rotation”: Quaternion.Euler(0,sledRot,0), “drive”: SlerpDrive});

Note the sledX, Z Rot variables are all floats, could this be the problem?

Thanks for any help!

Did a bit more experimentation with it, if I do each command separately (e.g. move then rotate) using Ani.Mate.To(… ) it works fine, but obviously looks wrong!

Anyone know what the problem is? I’ve not had much experience with Unity so any help is always appreciated :slight_smile:

The drive you set applies to all properties you try to animate in the call. That means you can only mix animations that use the same drive.

The SlerpDrive (S stands for spherical) is only available to Quaternions. It then tries to cast anything you pass to a Quaternion, which fails for Vector3 in this case.

You’ll have to use two separate calls in this case.

Ok thanks, is there another way I can do both at once then? It really does look awful the way it’s running at the moment!

bump

Both at once? Why does it look awful?

Do you possibly yield both calls and end up with two consecutive animations?

Ani.Mate.To(this.transform, 0.5, {"rotation": Quaternion.Euler(0,sledRot,0), "drive": SlerpDrive});
yield Ani.Mate.To(this.transform, 0.5, {"position": new Vector3(sledX,2.5,sledZ)});

This should work fine and there’s no difference between calling AniMate multiple times versus putting all animations in one call.

(Unless you use yield, in which case Unity waits for the animation to finish before starting the next one).

That worked fantastically thank you!

(Incidentally the reason it looked awful was that it was supposed to be rotating smoothly round a corner, instead it moved in a straight line then rotated lol)