x


Add Mixing Transform Doesn't Work!!

Hi

I've made this work on a character currently in my scene, but I just can't get it to work on the newest character I have added.

Here is the scripting I have been using

function Start () { animation["machineGunShoot"].layer = 14; animation["laserShoot"].layer = 14;

var mixShootLaserGun : Transform = transform.Find("waistM/back1M/back2M/RclavicleM/RshoulderM/RelbowM/RwristM/Rcannon1M");

animation["laserShoot"].AddMixingTransform(mixShootLaserGun);

var mixMachineGun : Transform = transform.Find("waist/back1/back2/Lclavicle/Lshoulder");

animation["machineGunShoot"].AddMixingTransform(mixMachineGun);

}

function Update () { if (Input.GetAxis("R_Trigger") > 0.1 && animation.IsPlaying("idle"))

    animation.Play("laserShoot");

}

Can anyone see any problems with what I have done? Or help me understand why it isn't working?

Thanks

more ▼

asked Apr 06 '12 at 05:58 PM

Joevis gravatar image

Joevis
1 9 13 13

What's wrong? Are you playing an idle/walk on a lower layer, which should "show through" but isn't (body is just frozen?) That would mean the mixAnim didn't take. Otherwise, maybe it is working, but something else is bad. Can you have Start just play shoot and idle, to check?

Can you check whether mixShootLaserGun is null (path spelled wrong)? UnityScript sometimes won't complain -- just won't do anything.

Apr 07 '12 at 04:18 PM Owen Reynolds

yeh I'm playing an idle animation on a lower layer.

When the script runs I get an error:

NullReferenceException UnityEngine.AnimationState.AddMixingTransform (UnityEngine.Transform mix) mechGun.Start () (at Assets/Mech Scripts/mechGun.js:9)

Apr 07 '12 at 04:22 PM Joevis

A null reference means it couldn't find something -- probably a bad path. Try printing mixMachineGun and checking each part: Debug.Log(transform.Find("waist"); and so on, until it says it can't find it.

Apr 08 '12 at 06:39 AM Owen Reynolds

Ok, how do I go about getting it to print something if it finds "waist"?

Sorry if it's a stupid question but I'm very new to coding :)

Apr 08 '12 at 07:55 PM Joevis

It's ok now :) I managed to sort it! It was an error with the path, I had missed out a bone! Duuh!

Apr 08 '12 at 08:47 PM Joevis
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

Not sure if this is related, but whenever I set AnimationState.layer to anything other than the default (0), I get a null reference exception.

Try removing the part where you change the 'animation["animName"].layer' at the start and see if the exception goes away.

more ▼

answered May 12 '12 at 06:37 PM

Moj gravatar image

Moj
0 1 1 2

(comments are locked)
10|3000 characters needed characters left

I think you missed some ( and ).

Try with that :

function Update () { if ((Input.GetAxis("R_Trigger") > 0.1) && (animation.IsPlaying("idle")))

    animation.Play("laserShoot");
}
more ▼

answered Apr 08 '12 at 10:48 PM

DJSwiti gravatar image

DJSwiti
105 6 8 9

(comments are locked)
10|3000 characters needed characters left

The code you're using before the Update function never gets used because you're just playing your standard lasershoot animation. add Debug.Log("Laser Shooting"); before the animation.play("laserShoot"); to see if the if statement is executed.

more ▼

answered Apr 07 '12 at 09:13 AM

garner gravatar image

garner
120 1

(comments are locked)
10|3000 characters needed characters left

I just tried that, and the animation is playing. It just isn't isolating the bones I want to play the animation on :/

It should work, because I used the same code for a character in the same game (obviously defining different bones) I just don't understand why it will work for one character and not for another!

more ▼

answered Apr 07 '12 at 03:30 PM

Joevis gravatar image

Joevis
1 9 13 13

These can be easier to read if you put short replies to someone as a comment on theirs.

Apr 07 '12 at 04:19 PM Owen Reynolds
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5081
x3790
x1278
x86
x12

asked: Apr 06 '12 at 05:58 PM

Seen: 1621 times

Last Updated: May 08 at 09:13 PM