private void OnCollisionEnter(Collision collision) { //print("collide with " + collision.gameObject.layer); // We give player control only when player land on ground if (collision.gameObject.layer == 8) { //bool isOnGroundBefore = m_isOnGround; IsOnGround = true; //print("Land on ground"); //if (isOnGroundBefore == false && onLandOnGround != null) //{ // onLandOnGround(collision.relativeVelocity); //} } else if (collision.gameObject.layer == 9) { if (collision.transform.parent.GetComponent <Flower>().HasLanded == false) { IsOnFlower = true; } } else { Rig.AddForce(collision.impulse * 0.2f, ForceMode.Impulse); } }
public void Jump() { //Jump the vehicle by adding for in the Y axis, using impulse force mode //This force mode can be changed but this method will increase the force base on the speed Rig.AddForce(new Vector3(0.0f, 20.0f, 0.0f), ForceMode.Impulse); //Reset the grounded boolean, so that the vehicle wont double jump IsGrounded = false; }
public void MoveVehicle(Vector3 moveDirection) { //Add force to the body of the object //This will send the object forward Rig.AddForce(moveDirection); }