private void HandleAccelerate(InputAction.CallbackContext obj) { activeStatus |= AccelerationStatus.AccelPressed; if (!activeStatus.IsDeAccelerationPressedFirst()) { activeStatus |= AccelerationStatus.AccelPressedFirst; } if (activeStatus.IsAccelerationPressedFirst() && !sendStatus.IsAccelerationPressed()) { sendStatus = AccelerationStatus.AccelPressed; wheelController.Accelerate(); } }
// Update is called once per frame void FixedUpdate() { //horizontal = Input.GetAxis("Horizontal"); //vertical = Input.GetAxis("Vertical"); localVel = transform.InverseTransformDirection(rigidbody.velocity); if (localVel.z < stopThreshold) { stopped = true; } else { stopped = false; } if (horizontal != 0f) { wheelController.Turn(horizontal, turnTorque, stopped); } else if (wheelController.turning) { wheelController.StopTurn(); } if (vertical > 0f) { wheelController.StopBrake(); wheelController.Accelerate(accelerateTorque * vertical); } else if (vertical < 0f) { wheelController.Brake(brakeTorque); } else { wheelController.StopAccelerate(); wheelController.StopBrake(); } //if no more than 2 wheels on ground, stabilize vehicle (bring x and z rotations smoothly back to original) int numGroundedWheels = 0; foreach (WheelData d in wheels.GetComponent <WheelController>().wheels) { if (d.col.isGrounded) { numGroundedWheels++; } } if (numGroundedWheels <= wheels.GetComponent <WheelController>().wheelCount / 2) { StabilizeVehicle(); } //Debug.Log("stopped: " + stopped); }