- Home /
Question by
Lexo18 · Apr 27, 2015 at 01:16 AM ·
jumpingcharacter controller
Character controller jumping is unresponsive
I made this script and it's supposed to use the T butting to jump but it will only jump about 1/3 of the time
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float curSpeed;
public float acceleration = 5;
public float decceleration = .2f;
public float jump = 20;
public float gravity = 21;
public float airAcceleration = 2.5f;
public float jumpAllowTime = .1f;
float jumpAllowTrack;
float moveSmooth;
CharacterController cont;
bool run = false;
Vector3 curMove;
float walkMoveV;
float runMoveV;
float stopMoveV;
float airAccelerationV;
private Stats Player;
void Awake (){
Player = GetComponent<Stats>();
}
// Use this for initialization
void Start () {
cont = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
if(Input.GetKey (KeyCode.A) || Input.GetKey (KeyCode.D))
run = true;
else
run = false;
curMove = new Vector3(curSpeed, curMove.y, 0);
//sprint and movement.
if(run == true && Input.GetKey (KeyCode.LeftShift))
curSpeed = Mathf.SmoothDamp(curSpeed, Input.GetAxisRaw ("Horizontal") * Player.runSpeed, ref walkMoveV, moveSmooth);
else if (run == true)
curSpeed = Mathf.SmoothDamp (curSpeed, Input.GetAxisRaw ("Horizontal") * Player.speed, ref runMoveV , moveSmooth);
else
curSpeed = Mathf.SmoothDamp (curSpeed, 0, ref stopMoveV , moveSmooth);
if(Input.GetKeyDown (KeyCode.T) && jumpAllowTrack >= 0)
curMove.y = jump;
if(cont.isGrounded){
curMove.y=0;
moveSmooth = acceleration;
jumpAllowTrack = jumpAllowTime;
}
if(!cont.isGrounded){
curMove -= new Vector3(0, gravity * Time.deltaTime, 0);
moveSmooth = airAcceleration;
jumpAllowTrack -= Time.deltaTime;
}
cont.Move(curMove*Time.deltaTime);
}
}
How can I fix this?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613194107im_/https://answers.unity.com/themes/thub/images/avi.jpg)