- Home /
Fixed the problem myself
Character not jumping high enough
Okay I've been working on this singular issue for weeks now. I'm using Mixamo animations and for some reason my jump only goes slightly up and comes back down, the height doesn't match the default animation's at all. I've tried adjusting gravity and velocity but nothing changes. I've totally redone my controller script, written it without the Character Controller component and used only Rigidbody but it didn't work at all at that point. I've searched the forms, watched videos, tried everything but this script is the only method that has worked the best for me? This is what I have written so far, cutting off some of the extra animations.
float speed = 2;
float rotSpeed = 150;
float rot = 0f;
float gravity = 0;
Vector3 moveDir = Vector3.zero;
CharacterController controller;
Animator anim;
private bool isGrounded;
private bool IsFalling;
private float m_JumpSpeed = 60f;
private IEnumerator Jump()
{
float gravity = -Physics.gravity.y;
float jumpVelocity = m_JumpSpeed;
float initialY = transform.position.y;
while (transform.position.y >= initialY)
{
transform.Translate(0f, jumpVelocity * Time.deltaTime, 0f);
jumpVelocity -= gravity;
yield return null;
}
transform.position = new Vector3(transform.position.x, initialY, transform.position.z);
}
void Start()
{
controller = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
}
void Update()
{
Movement();
}
void Movement()
{
if (controller.isGrounded)
{
if (Input.GetKeyDown(KeyCode.Space))
{
anim.SetTrigger("Jump");
}
And here is where I call all the other animations and such. I'm sure there's a lot of extra stuff as I've taught myself everything through tutorials and forums and redoing everything a thousand times. But if anyone has any ideas as to why my jump might be so terrible please let me know. Thanks!
Answer by Kudorado · Jan 11, 2019 at 03:05 AM
I guess a problem cause you are using Apply root motion
in your Animator
.
If yes then trying to unset Apply root motion
, tick Loop Pose
in your Animation
and set it height's via script, hope it could help you.
When I unset apply root motion he wouldn't move at all anymore??
You need to change it manually via script, then you can modify any height you want.
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
{
anim.SetTrigger("Jump");
//you need to change you height manually here.
}
Follow this Question
Related Questions
How to increment value of axis when something happens 2 Answers
Enemy Health Script Working On One Enemy Not Multiples 2 Answers
How to add text values to a list 2 Answers
Help me with this code proplem,,Almost finish my game please help this once 3 Answers
Standard Asset FP Controller not moving 0 Answers