system
1
Hey there.
I'm trying to set it up so that, when I press Shift, the character plays a certain animation and dashes forward a bit (Forward being to the right or left, depending on which direction you were facing). I assume that you would use transform.Translate for that, but it's not doing anything. The code is as follows:
var tackleSound : AudioClip;
function Update () {
var isDoor : GateOpen = GetComponent(GateOpen);
if (Input.GetButtonDown ("Action")) {
animation.Play ("shouldertackle");
transform.Translate(Vector3(5, 0, 0) * Time.deltaTime);
audio.PlayOneShot(tackleSound);
}
}
I've also tried most of the code snippets from the website's scripting reference, none of which have worked either. What's with this?
Eric5h5
2
GetButtonDown only runs once when the button is first pressed.
Bampf
3
deltaTime is a tiny, sub-second value unless your framerate is really bad. Translate is probably working but it isn't moving the character very far. (You could test this by moving it a larger amount.)
Instead, you probably want to move a longer distance, gradually over time. A useful function for that is Lerp, and it's explained very well here:
http://answers.unity3d.com/questions/6949/can-someone-explain-how-using-time-deltatime-as-t-in-a-lerp-actually-works/6950#6950