Hi there, sometimes when I press the jump button the rigid body just ignore the command, I tried really hard but couldn’t get it fixed, can someone please help me?
using UnityEngine;
using System.Collections;
public class playerJump : MonoBehaviour {
public float jumpStrenght;
public bool doubleJump;
private float multiplier;
private int jumpCounter;
// Use this for initialization
void Start () {
multiplier = 100.0f;
if(doubleJump){
jumpCounter = 2;
}else{
jumpCounter = 1;
}
}
void FixedUpdate () {
if(Input.GetButtonDown("Jump")){
if(jumpCounter>0){
//decrease the jump counter untill it touches the ground
jumpCounter--;
jump(jumpStrenght);
}
}
}
void OnCollisionEnter(Collision other){
//Sets the double jump property
if(other.gameObject.CompareTag("Terrain")){
if(doubleJump){
jumpCounter = 2;
}else{
jumpCounter = 1;
}
}
}
public void jump(float strenght){
rigidbody.AddForce(new Vector3(0,Time.deltaTime*strenght*multiplier,0),ForceMode.Impulse);
}
}
if needed I can post my player controller script too.