Here is my player controller I have been working on.
Everything works fine, finally found out that using Interpolation for jumping smoothed out the jitteryness of jumping, which thankfully I found.
But now I am running into a stump in the road.
I can still jump fine when I stand still, however, if I start moving, I jump maybe not even half way as high. I tried using Extrapolate or whatever, it was worse than not having Interpolate, but here is my code.
//private CapsuleCollider col; // This is the Collider for Player.
private Animator anim; // This is the Animator for Player.
public float Speed = 5.0f;
public float TurnSpeed = 5.0f;
public float jumpHeight = 10.0f;
public bool canJump;
public bool Transition = false;
// Use this for initialization
void Start () {
anim = gameObject.GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (!Transition) {
if (Input.GetKey (KeyCode.W)) {
transform.Translate (Vector3.forward * Speed * Time.deltaTime);
anim.SetFloat ("Speed", 1f);
} else {
anim.SetFloat ("Speed", 0f);
}
if (Input.GetKey (KeyCode.S)) {
transform.Translate (Vector3.back * Speed * Time.deltaTime);
anim.SetFloat ("WalkBack", -1f);
} else {
anim.SetFloat ("WalkBack", 0f);
}
if (Input.GetKey (KeyCode.A)) {
transform.Rotate (0,-3,0 * Time.deltaTime);
}
if (Input.GetKey (KeyCode.D)) {
transform.Rotate (0,3,0 * Time.deltaTime);
}
}
}
void FixedUpdate(){
if (Input.GetKeyDown (KeyCode.Space) && canJump == true) {
if (canJump) {
anim.SetBool ("Jump", true);
transform.rigidbody.AddRelativeForce (Vector3.up * jumpHeight);
Physics.gravity = new Vector3 (0, -20, 0);
}
}
}
void OnCollisionEnter(Collision col){
if (col.gameObject.tag == "Map") {
anim.SetBool ("Jump", false);
}
}
}
Please, if you can help me, all would be greatly appreciated!