Idle Speed

Hi There Guys
another simple one …that is doing my head in

basically the code below is attatched to a character collider and the code below takes variables from another script that is also attatched to the character collider(code Below works fine!

now what I am trying to do is create a script that accesses the same variables as the script below but from a seperate trigger collider on another GameObject…as I want a separate set of Idles to be used and a different walk…so your help would be greatly appreciated… I have tried using GetComponent in my trigger script but I think I am getting the syntax wrong…etcetera not even sure if i should be using get component…

//////////////////////////////////////

//// IDLE-CODE//////////////

function Update ()
{
var marioController : standardplayercontrol = GetComponent(standardplayercontrol);
var currentSpeed = marioController.GetSpeed();

// Switch between idle and walk
if (currentSpeed > 0.1)//was 0.1

animation.CrossFade(“walk”);
else
animation.CrossFade(“idle”);

}

I think that what you’re saying is that you want to access the ‘currentSpeed’ variable from another GameObject that is a trigger? In that case you maybe should try this:

function OnTriggerEnter(other : Collider){
 var variable1 :  float;
 //Gets the variable from the object that triggered this trigger 
 variable1 = other.gameObject.GetComponent("TheScriptsName").currentSpeed;
}

Oh and remeber that you have to have a rigidbody attached to the trigger. If you don’t want the trigger to move. make it kinematic.

Thanks for the quick reply Lime x…yes the current speed variable is the variable I wish to access will give your script a go and see how I get on cheers!

No problem I hope it works out for you :smile:

Hi There just got a error message unknown identifier CurrentSpeed when I used the above suggestion…?

//TRIGGER ANIMATION PARAWALK////

var emelly : GameObject;//the game object witth the collider/and new animations

function OnTriggerEnter (other : Collider) {
if (other.CompareTag (“Player”)) {

var variable1 : float;
//Gets the variable from the object that triggered this trigger
variable1 = emelly.gameObject.GetComponent(standardplayercontrol).CurrentSpeed;
if (CurrentSpeed> 0.1)

emelly.animation.CrossFadeQueued(“parawalkloop”,0.3,QueueMode.PlayNow);

else

emelly.animation.CrossFadeQueued(“paraidle”,0.3,QueueMode.PlayNow);

}
}

Have you checked that it’s not the capital letter ‘C’ in CurrentSpeed since I saw that in your first script you use a small ‘c’ in currentSpeed?

no its not that Buddy first thing I checked…I was looking at the example you gave me…and there is no reference to getspeed…is that the issue…? …

I solved the problem in another way…but thanks for taking the time out to help
Lime _x

Ah well, I’m glad that you solved the problem. :slight_smile: