- Home /
How to make character controller forward jump a certain distance?
I want to make a character perform a smooth forward jump a certain distance when I press "j" button. The character has character controller attached to it and using boolean animations. I have tried everything put nothing seems to work.
if (Input.GetKey("j"))
{
animator.SetBool("isJumping", true);
characterController.Move(transform.TransformDirection(Vector3.forward) *
Time.deltaTime*20f);
}
if (!Input.GetKey("j"))
{
animator.SetBool("isJumping", false);
}
Answer by IcookTacos · Jan 23 at 09:28 PM
Maybe you can describe the issue. What is wrong with the current implementation you posted. What behaviour are you getting vs what you want. Is this for a 3d or 2d environment?
Just looking at the code you posted I don't see any force that would move the character up in a jumping fashion, I just see you moving it forward.
It is a 3d game. With the current implementation, the user is not able to jump a "X" distance forward. The user is only jumping vertically and not moving forward. I want the character to move a certain forward while jumping.
"Just looking at the code you posted I don't see any force that would move the character up in a jumping fashion, I just see you moving it forward." The jumping action is performed by the jumping animation I downloaded from mixamo. I want the character to move forward while it is in the jumping animation.
I see.
I'm not gonna tell you how to design your movement but having the animation control the jumping sounds fishy. Have you ensured that the character collider is moving together with the animation? It could be possible that the animation is playing but the character collider isn't impacted. I have never really used the character controller before but it looks like the code you posted simply tries to move the character forward with a certain delta while the ''j'' key is active.
I can't really give any advice on how to fix it given the solution you are using. I have done a similar jump but using rigidbody and unitys physics engine. Here is a example:
float y = playerStats.velocity_Y;
float z = playerStats.velocity_Z;
float x = 0;
this.GetComponent<Rigidbody>().AddRelativeForce(new Vector3(x,y,z));
This shoots the character in a arch forward similar to what I think you want.
Another tip is to start without any animations since you want to secure all the basic movements and motions before adding on any "visual" layer to your character. A good practice is to keep the animations and movement separate.
Your answer
Follow this Question
Related Questions
Character will not go from Ide to Walk 1 Answer
Jump axis from 0 to max 1 Answer
How to make char animation idle 0 Answers