void _useItem() { int aimMethod = slot.getAimMethod(); if (inputMethod == 2 && player.GetButton("Use Item")) { Debug.Log(player.GetAxis("Aim Item")); if (aimMethod == 1 && (player.GetAxis("Aim Item") < 0)) { slot.setAim_rot(new Vector3(0, 180, 0)); } else { slot.setAim_rot(new Vector3(0, 0, 0)); } slot.use(); } else if (inputMethod == 0 && Input.GetKey(KeyCode.E)) { if (aimMethod == 1) { slot.setAim_rot(new Vector3(0, 0, 0)); } slot.use(); } else if (inputMethod == 0 && Input.GetKey(KeyCode.Q)) { if (aimMethod == 1) { slot.setAim_rot(new Vector3(0, 180, 0)); } slot.use(); } else if (inputMethod == 1 && Input.GetKey(KeyCode.RightControl)) { if (aimMethod == 1) { slot.setAim_rot(new Vector3(0, 0, 0)); } slot.use(); } else if (inputMethod == 1 && Input.GetKey(KeyCode.RightShift)) { if (aimMethod == 1) { slot.setAim_rot(new Vector3(0, 180, 0)); } slot.use(); } }
// Update everything void FixedUpdate() { // Mesure current speed speed = transform.InverseTransformDirection(_rb.velocity).z * 3.6f; // Get all the inputs! if (isPlayer) { // Accelerate & brake if (throttleInput != "" && throttleInput != null) { throttle = ((player.GetButton(throttleInput) | Input.GetKey(KeyCode.W)) ? 1 : 0); //- GetInput(brakeInput); } // Boost // boosting = (GetInput(boostInput) > 0.5f); // Turn steering = turnInputCurve.Evaluate(player.GetAxis(turnInput)) * steerAngle; if (Input.GetKey(KeyCode.A)) { steering -= 5; } if (Input.GetKey(KeyCode.D)) { steering += 5; } // Use Item useItem = player.GetButton("Use Item"); // Item Aim itemAim = player.GetAxis("Aim Item"); // Dirft // drift = GetInput(driftInput) > 0 && _rb.velocity.sqrMagnitude > 100; // Jump // jumping = GetInput(jumpInput) != 0; } // Direction foreach (WheelCollider wheel in turnWheel) { wheel.steerAngle = Mathf.Lerp(wheel.steerAngle, steering, steerSpeed); } foreach (WheelCollider wheel in wheels) { wheel.brakeTorque = 0; } // Enables friction foreach (WheelCollider wheel in wheels) { _rb.drag = 0; WheelHit hit; if (wheel.GetGroundHit(out hit)) { _rb.drag += hit.collider.material.dynamicFriction; } } // Constant acceleration Cart_speedup(6f); // Use Item if (useItem) { if ((itemAim < 0)) { slot.setAim_rot(new Vector3(0, 180, 0)); } else { slot.setAim_rot(new Vector3(0, 0, 0)); } slot.use(); } // Handbrake if (handbrake) { foreach (WheelCollider wheel in wheels) { // Don't zero out this value or the wheel completly lock up wheel.motorTorque = 0.0001f; wheel.brakeTorque = brakeForce; } } else if (Mathf.Abs(speed) < 4 || Mathf.Sign(speed) == Mathf.Sign(throttle)) { foreach (WheelCollider wheel in driveWheel) { wheel.motorTorque = throttle * motorTorque.Evaluate(speed) * diffGearing / driveWheel.Length; } } else { foreach (WheelCollider wheel in wheels) { wheel.brakeTorque = Mathf.Abs(throttle) * brakeForce; } } // Jump if (jumping && isPlayer) { if (!IsGrounded) { return; } _rb.velocity += transform.up * jumpVel; } // Boost if (boosting && allowBoost && boost > 0.1f) { _rb.AddForce(transform.forward * boostForce); boost -= Time.fixedDeltaTime; if (boost < 0f) { boost = 0f; } if (boostParticles.Length > 0 && !boostParticles[0].isPlaying) { foreach (ParticleSystem boostParticle in boostParticles) { boostParticle.Play(); } } if (boostSource != null && !boostSource.isPlaying) { boostSource.Play(); } } else { if (boostParticles.Length > 0 && boostParticles[0].isPlaying) { foreach (ParticleSystem boostParticle in boostParticles) { boostParticle.Stop(); } } if (boostSource != null && boostSource.isPlaying) { boostSource.Stop(); } } // Drift if (drift && allowDrift) { Vector3 driftForce = -transform.right; driftForce.y = 0.0f; driftForce.Normalize(); if (steering != 0) { driftForce *= _rb.mass * speed / 7f * throttle * steering / steerAngle; } Vector3 driftTorque = transform.up * 0.1f * steering / steerAngle; _rb.AddForce(driftForce * driftIntensity, ForceMode.Force); _rb.AddTorque(driftTorque * driftIntensity, ForceMode.VelocityChange); } // Downforce _rb.AddForce(-transform.up * speed * downforce); }