- Home /
SimpleMove/Move moving random distance
Gentlemen!
I'm trying to write this code that will make the player character perform a shoulder tackle attack wherein they charge forward a small distance. The current code is as follows:
var tackleSound : AudioClip;
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
if (Input.GetButtonDown ("Action")) {
animation.Play ("shouldertackle");
controller.Move(transform.TransformDirection(0, 0, 4));
audio.PlayOneShot(tackleSound);
}
}
Now, this works to some extent: The character charges forward, stopping when he hits an obstacle. But about every third or fourth button press, he'll shoot forward about four times as far, and passes through everything. Any idea what's causing it?
I would start by placing a print("action button down") in the button down IF statement to see if the function is called several times.
Debug.Log("Action button down"); in the if statement, and I'm agreeing with Anxo.
Should be ok, since Input.GetButtonDown doesn't repeat. Docs say "It will not return true until the user has released the key and pressed it again."
Also check the CollisionFlags being returned from controller.$$anonymous$$ove, maybe that will give you a clue as to what's happening.
Your answer
Follow this Question
Related Questions
Any way to disable SimpleMove's sliding? 1 Answer
Move() function doesn't work on character controller! 0 Answers
Switching from SimpleMove to Move 1 Answer
Odd touch input problem 0 Answers