Help With Scripting

Hey Guys. I’ve recent’y gotten into scripting and things have been going pretty well. I just have one question. I have a script written so that when you push the space bar the camera jumps to a first person view. And it works, sort of. you see, the camera only goes to that view for a split second and then goes back to third person. Can someone help me with this? BTW here is the script:

var location : Transform;
var defaultTarget : Transform;
function Update () {

if(Input.GetButtonDown(“Jump”))

GetComponent(SmoothFollow).target = location;
else GetComponent(SmoothFollow).target = defaultTarget ;

}

Try Input.GetButtonUp instead. Most likely the GetButtonDown is being fired numerous times so the result will be fairly random.

If you find that GetButtonUP is firing more than once as well then you’ll need to add a simple check to make sure it’s only firing once each time the user presses it. You can do this by saving the time the button was pressed and only setting a new target if it’s been longer than X number of seconds.

Thanks so much. It works perfectly.

Really? Replacing GetButtonDown() with GetButtonUp() fixed the problem? I wouldn’t have expected that. (GetButtonDown() shouldn’t fire multiple times for a single key press as far as I know, and in any case, it looks to me like the problem was due to a simple program logic error rather than using the wrong input function.)