Why is new Vector3 stronger when player is in the air?
I am trying to make a knock back script. When I walk into enemy the while grounded the player gets slightly bumped, but when I jump and hit the enemy the player goes much farther.
Here is my code (I have a script on the enemy to cause knock back and one on the player for resetting):
 public float xVel = 15f;
 public float yVel =  7f;
 public bool KnockedBack = false;
 private GameObject otherPlayer;
 void OnTriggerEnter (Collider other)
 {
     if (other.gameObject.tag == "Player")
     {    
         other.gameObject.GetComponent<Rigidbody> ().velocity = Vector3.zero;
         other.gameObject.GetComponent<Rigidbody> ().angularVelocity = Vector3.zero;
         other.gameObject.GetComponent<Rigidbody> ().velocity = new Vector3 (-xVel, yVel, 0f);
         KnockedBack = true;
         other.gameObject.GetComponent<ResetKnockBack> ().grounded = false;
         print (other.gameObject.GetComponent<ResetKnockBack> ().grounded);
     }
 }
 
               }
 public bool grounded = true;
 public GameObject opponent;
 void OnCollisionEnter (Collision other)
 {
     print (grounded);
     if (other.gameObject.tag == "Ground")
     {    
         StartCoroutine (resetTime ());
     }
     if (grounded && opponent.GetComponent<KockbackPlayer> ().KnockedBack == true)
     {
         other.gameObject.GetComponent<KockbackPlayer> ().KnockedBack = false;
         this.gameObject.GetComponent<Rigidbody> ().velocity = Vector3.zero;
     }
 
         
 }
 IEnumerator resetTime ()
 {
     yield return new WaitForSeconds (0);
     //grounded = true;
 }
 
               }
               Comment
              
 
               
              Your answer