- Home /
Influencing Third Person Controller's walk speed from another method?
Hey everyone,
So I'm working on a little worm game where the user competes with another worm for apples. You can see the rough version of it here: http://www.pages.drexel.edu/~jhp33/WebPlayer.html
Currently the worm uses the default third person character movement and controller from Unity's premade scripts.
I'm not at a computer now, but I think the variable that defined walk speed was something like "maxWalkSpeed." I could be wrong but it's something along those lines.
Anyway, I wanted to make it so that when a golden apple is eaten, the user gets a five second speed boost.
My question is: how do I influence maxWalkSpeed from outside the third person controller? I tried using a gameObject.ThirdPersonController.maxWalkSpeed+=3 type approach (something like that, not at my workstation so I can't see the exact syntax and names) but it didn't seem to work. Would I have to make that change within the character controller itself? A code example would help me get a grasp on what I'm missing.
I assume the five second part could be accomplished by a Time.deltaTime if statement, but I'd have to play around with it a bit more with a working speed boost to find out.
Thanks Comm-Unity! J-Patt
Answer by SomeGuy22 · Aug 27, 2012 at 09:44 PM
You'd want to access the walk speed by doing
if (go)
gameObject.GetComponent(CharacterMotor).movement.maxForwardSpeed = appleSpeed;
else
gameObject.GetComponent(CharacterMotor).movement.maxForwardSpeed = defaultSpeed;
Where appleSpeed and defaultSpeed are variables. For the five-second part, you'd want to do a function:
function OnGetGoldenApple ()
{
go = true;
yield WaitForSeconds (5);
go = false;
}
This was close; I ended up having to do:
if (go) playerContainer.GetComponent(ThirdPersonController).runSpeed = 20;
else playerContainer.GetComponent(ThirdPersonController).runSpeed = 10;
I am, but the command wasn't working for some reason. Shifting the runSpeed was functional enough. As I develop more complex games, I'll look into exactly why that was and perhaps update this with a better explanation of what I was doing wrong ha ha.
I'm using a charactermotor and a thirdpersoncontroller in tandem; does that lead to any issues? The Unity prefab seemed to automatically add both in.
No. In fact they are supposed to work together, just like FPSInputController. I guess you can adjust the runSpeed but I wouldn't get used to it--the Character$$anonymous$$otor is where I do most... all changes for $$anonymous$$ovement.
What sort of error were you getting when you tried getting the Character$$anonymous$$otor?
Your answer
Follow this Question
Related Questions
Mathf.Smoothdamp, need help troubleshooting! 0 Answers
How to accelerate and improve the rendering on iPhone ? 0 Answers
update() too fast? 2 Answers