- Home /
charactercontroller.isgrounded not working!!
Hi I'm using this code and it's not working although the character is on the ground!! It Does not work when he is on the train or on a mesh collider or on simple cube collider My Character is moving all the time And is using a character motor too!
if(Input.GetKeyDown("a") && controller.isgrounded)
{
animation.Play("ollie_flip");
transform.localPosition.x-=10;
}
What is the problem?!?! Let me tell You that controller is a variable of type : CharacterController!! Which was Assginged like this: controller = GetComponent(CharacterController);
Does anybody needs $$anonymous$$y Full Script?!?! to Answer ;(
Answer by Mander · Aug 24, 2012 at 03:48 PM
add some gravity. that will help u. cuz sometimes it doesn't work with out it.
What?!? Do u mean i should attach a rigidbody to the player!! Explain Please!! :O
I Attached a RigidBody to the player still not working!!
no. with the character controller u can do this ezly. just add a gravity var so it is making ur CharacterController touch the ground. this is an example on how i do it for my 2.5D game. C#:
vars:
public float gravity = 5.0f;
private Vector2 moveDirection = Vector2.zero;
inside Update():
moveDirection = new Vector2(Input.GetAxis("Horizontal"), 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection.y -= gravity * Time.deltaTime;
did i explain myself? xD
Thank you for answering and also that usefull answer but the problem was from this that isgrounded must be written like this: isGrounded not isgrounded! but anyway that script can be really usefull! :)
I have the same problem. Gravity doesn't work. When the player is moving, isGrounded is false. No idea why, but I'd sure like to know
Your answer
Follow this Question
Related Questions
how do I create a character 2 Answers
Moving character to a specific point ? 0 Answers
Platform moves when character steps on it 1 Answer
How to "Increase score with Y axis"? 1 Answer
My character jumps infinitely, even when in mid-air 1 Answer