- Home /
Character with controller flies off map.
I have just added a character controller and now every time I hit play the character starts flying off the map instantly. Anyone know how to fix that?
[1]: /storage/temp/143827-bildschirmfoto-2019-07-31-um-214919.png
I would take off the rigid body, as a character controller has its own.... behind the scenes.
Need some code in that playerController you have then. :)
Answer by Vega4Life · Jul 31, 2019 at 08:10 PM
So, you are adding jumpForce to your moveDirection.y every frame... thats the issue. Should it be inside the if statement for jumping?
move this out of the if statement: moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); and put it above the if check for jumping - so you can move.
I deleted the code and he doesn't fly off but now he can't move.
move this out of the if statement: moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); and put it above the if check for jumping.
like this? because now i can walk perfectly. But i can't jump.
[1]: /storage/temp/143830-bildschirmfoto-2019-07-31-um-223747.png
Answer by Magso · Jul 31, 2019 at 08:20 PM
You've set moveDirection.y
to the jumpForce
value, thus a constant movement upwards. moveDirection.y
needs to come back down to allow the character to fall. You need something like this.
if(Input.GetButtonDown("Jump") && controller.isGrounded){
moveDirection.y = jumpForce;
}
else if(!controller.isGrounded){
moveDirection.y -= yourGravityAmount;
}
else{
moveDirection.y = 0;
}
That's peculiar. Try
else if(controller.isGrounded){
moveDirection.y = 0;
}
nope. doesn't work
[1]: /storage/temp/143831-bildschirmfoto-2019-07-31-um-224647.png
Your answer
Follow this Question
Related Questions
Unity Flash, character jumps when the controller touches a step 0 Answers
Character - Collider With Scene 0 Answers
Character controller movement 1 Answer
Character constantly Bouncing issue 0 Answers
Make a character controller shake. 2 Answers