- Home /
Player cannot jump if not in update or fixed update
I'm almost new in unity but not so noob. if I call this in FixedUpdate or Update, it works perfectly. This is my code:
void ChickenJump(){
print ("touch");
if (Grounded&&Input.GetKeyDown(KeyCode.Space)) {
chickenbody.velocity = new Vector2 (0.0f, jumpRange);
}
but if I use this code and called with a button, it does't work!
public void ChickenJump(){
print ("touch");
if (Grounded) {
chickenbody.velocity = new Vector2 (0.0f, jumpRange);
}
}
The print is showing, meaning it is called, but the jump does't work!
please help..
If grounded is a public variable you will be able to see it in the editor. If not, try using Debug.Log(Grounded);
in ChickenJump(), Update(), or FixedUpdate(). After the problem is fixed, be sure to stop writing it to the console, because it can slow the game down. If Grounded is never set to true, then something has gone wrong. Is the ChickenJump() void getting called when you press the jump key or not?
Answer by Fobri · Dec 17, 2016 at 07:06 PM
Grounded is not true then. Are you using charactercontroller? because if not you should since it contains a check for player being grounded and you don't need to do it yourself.
https://docs.unity3d.com/ScriptReference/CharacterController-isGrounded.html
Answer by iahr · Dec 19, 2016 at 08:30 AM
Ok, I recreated the script in a new project. I only try that specific problem..... it works, and it jump smoothly like i wanted to. I don't know why, this happened to me every time. I think something is wrong with my Unity application.
Your answer
Follow this Question
Related Questions
Character not jumping high enough 1 Answer
rigidbody.AddForce jump, different heights each time 1 Answer
Addforce while compensating others 1 Answer
Rigidbody.velocity giving weird result 0 Answers
Character Jump Control 1 Answer