Player State & Animator - Help Needed!

Hello guys,

I’ve run into a problem - and I don’t know what the solution is. And it’s a bugger to describe the problem.
The question is like this, how do I get control of the player animations to match the “player states” if you will? I can’t descibe it better than that.

I have a basic, and I mean really basic project in which I am trying to figure out the nuts and bolts of an FPS. So, far I have the idle state working correctly, the walk states are all working off it, but, I cannot get the down/backward running state to show as i intend. It probably looks very clumsy but it the only thing I could come up with.

The conditional for gun_down → gun_run_down in the Animator is below:

The code is as follows - it’s long winded for clarity to me and error-checking and using the console:

#pragma strict

//attach script to the object that we want to apply the ""Change State"
//this is done by going to inpector for that object clicking on
//"Add Component" button at bottom of object -> Scripts then
//finding appropriate Script - ie "Change^State"

//Script to change state from idle to walk -> maybe run eventually
//script modified slightly - emphasis on slightly - from YouTube tutorial
//on mocap scripting

//doesn't really matter if internal or not
internal var anime: Animator;

//vars to get vertical horizontal movement
var v:             float; //vertical up/down arrows
var h:             float; //horzizontal (strafing) movement
var sprint:     float; //set value for sprinting
//boolean values for me to play with
var isDown:        boolean;
var isSprint:     boolean;
var DoubleDown:    boolean;


//get access to the animator
function Start () {
    //
    anime = GetComponent(Animator);
    }//-->end Start function


//get vertical and horizontal vars
function Update () {
    //print("sprint: "+sprint);
    v = Input.GetAxis("Vertical");
    h = Input.GetAxis("Horizontal");
    //r = Input.GetAxis("Sprinting");
    sprinting();
    //print("sprint: "+sprint);

    if(v < -0.1){
        isDown = true;
        print("Direction: down: "+isDown);
        }
    else{
        isDown = false;
        print("Direction not!: "+isDown);
        }

    if(isDown && isSprint){
        //both conditions are met
        DoubleDown = true;
        print("Both conditions are met");
        }
    else
        DoubleDown = false;

    print("DoubleDown: " + DoubleDown);

    }//-->end Update function.



//set the variable in the Animator to play correct animation
function FixedUpdate(){
    anime.SetFloat("Walk",v);
    anime.SetFloat("Str",h);
    anime.SetFloat("Running",sprint);

    anime.SetBool("DDown", DoubleDown);

    //should horizontal/strafing movement be used in access walk animation or
    //something different ?!?!?

    }//-->End FixedUpdate function


function sprinting(){
    if(Input.GetButton("Sprinting")){
        isSprint = true;
        sprint = .2;
        }
    else{
        isSprint = false;
        sprint = 0.0;
        }
    //print("Sprinting........................");
    }//-->End sprinting function

So, I must be not understanding how the SetBool value is sent and applies it to the Animator. The way I figure it the boolean value DoubleDown is true, when both conditions are met, so:

“if DDown = true”, which is does, according to the code, then it should play the next animation in the chain. So what am I not getting here?

And on top of all that I need to another animations for gun-aiming (ie down the scope) when Idle/Walking or both and I don’t have a clue how to do this! This Animator thing has turned my mind to mush.

So any help at all would be greatly appreciated :).

Cheers.

Is there any other information I can supply to help get an answer?

ok, I’ll have a stab at it. I guess gun_run_down means ‘running while gun pointing down’.

  1. the gun_run_down state only comes from idle state. I think the walk and run states should come from idle, and gun up or down should come from walk/run states.
  2. I think you’d be better off with two layers, one for upper body and one for lower body. then on lower body layer you’d have idle/walk/run and upper body layer gundown/gunup/aimleft/aimright. for the latter two you can use blend trees (maybe for the first two also)

That’s basically right - good guess from my pretty cryptic naming :p.

So the gun-run-down state in my example doesn’t really have anything to do with the gun_walking state at all?

After reading your reply, I managed to get the idle-> walk states through a 2D simple blend tree with “idle” in the middle, and walk for Up/Down/Left and Right directions around that, don’t really understand “why” that works!?! And then managed to get a run state tacked onto that, that goes in the main directions also.

I suppose I’ll try making a blend tree for the aiming as well and see how much I can stuff it up :).

I really like the idea of two layers as well when I get more proficient I’d like to try that :sunglasses:.