- Home /
Question by
Delloy · Jul 25, 2020 at 07:12 PM ·
playerscript.jumpingcharacter controller
Why am I not jumping?
I currently have a character controller and this script attached but I'm not sure why I'm unable to jump higher? It plays the animation fine but whenever I increase the Jump on the inspector it doesn't affect anything.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
private Animator anim;
private CharacterController controller;
public float speed = 600.0f;
public float turnSpeed = 400.0f;
private Vector3 moveDirection = Vector3.zero;
public float gravity = 20.0f;
public float jumpSpeed = 8.0f;
void Start () {
controller = GetComponent <CharacterController>();
anim = gameObject.GetComponent<Animator>();
}
void Update (){
anim.SetFloat("horizontal", Input.GetAxis("Horizontal"));
if (Input.GetKey ("w")) {
anim.SetInteger ("AnimationPar", 1);
} else {
anim.SetInteger ("AnimationPar", 0);
}
if(Input.GetKey ("s"))
{
anim.SetInteger("AnimationPar", -1);
}
if (controller.isGrounded && Input.GetButton("Jump"))
{
moveDirection.y += Mathf.Sqrt(jumpSpeed * -3.0f * gravity);
anim.SetTrigger("isJumping");
}
else if(Input.GetButtonUp("Jump"))
{
anim.ResetTrigger("isJumping");
}
if(controller.isGrounded){
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
}
float turn = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
controller.Move(moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
}
}
Anyone have any idea why this isn't working? Thanks
Comment
Answer by Eno-Khaon · Jul 25, 2020 at 08:43 PM
moveDirection.y += Mathf.Sqrt(jumpSpeed * -3.0f * gravity);
Are you jamming your character into the ground instead of jumping (up) off of it?
Thank you for your reply, how would I go about changing this?
Your answer
Follow this Question
Related Questions
how to keep mid air velocity using character controller? 0 Answers
Character Controller Upward Movement Along Concave Surface 0 Answers
I can't do that my character jumps while running 0 Answers
Jumping not always work 2 Answers
how can i prevent pause menu? 0 Answers