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.