Beispiel #1
0
        public void Update(VehicleController vc)
        {
            if (!enabled)
            {
                return;
            }

            if (solidAxle)
            {
                if (axleBones.Count == vc.axles.Count && axleBones != null)
                {
                    for (int i = 0; i < axleBones.Count; i++)
                    {
                        // Adjust axle position
                        Axle axle = vc.axles[i];

                        Vector3 position = (axle.leftWheel.WheelController.springTravelPoint + axle.rightWheel.WheelController.springTravelPoint) / 2f;
                        axleBones[i].position = position;
                        axleBones[i].LookAt(axle.leftWheel.WheelController.springTravelPoint, vc.transform.up);
                        axleBones[i].Rotate(0, 90, 0);

                        // Adjust camber
                        float camberAngle = VehicleController.AngleSigned(vc.transform.right, axleBones[i].right, vc.transform.forward);
                        axle.leftWheel.WheelController.SetCamber(camberAngle);
                        axle.rightWheel.WheelController.SetCamber(-camberAngle);
                    }
                }
                else
                {
                    Debug.LogError("Number of axle bones must be the same as the number of axles.");
                }
            }
            else
            {
                if (wheelBones.Count == vc.Wheels.Count && wheelBones != null)
                {
                    for (int i = 0; i < wheelBones.Count; i++)
                    {
                        wheelBones[i].position = vc.Wheels[i].WheelController.springTravelPoint;
                    }
                }
                else
                {
                    Debug.LogError("Number of wheel bones must be the same as the number of wheels.");
                }
            }
        }
Beispiel #2
0
        public void Update()
        {
            // Set camber only if it has not already been set by the WC3D's inspector and if axle is not solid (in which case camber is set automatically).
            if (!(geometry.isSolid || (geometry.camberAtBottom == 0 && geometry.camberAtTop == 0)))
            {
                leftWheel.WheelController.SetCamber(geometry.camberAtTop, geometry.camberAtBottom);
                rightWheel.WheelController.SetCamber(geometry.camberAtTop, geometry.camberAtBottom);
            }

            // Apply anti roll bar
            if (geometry.antiRollBarForce != 0)
            {
                float leftTravel  = leftWheel.SpringTravel;
                float rightTravel = rightWheel.SpringTravel;

                // Anti-roll bar is linear to prevent possible jitter at lower update rates.
                float arf = (leftTravel - rightTravel) * geometry.antiRollBarForce;

                if (leftWheel.IsGrounded && rightWheel.IsGrounded)
                {
                    vc.vehicleRigidbody.AddForceAtPosition(leftWheel.ControllerTransform.up * -arf, leftWheel.ControllerTransform.position);
                    vc.vehicleRigidbody.AddForceAtPosition(rightWheel.ControllerTransform.up * arf, rightWheel.ControllerTransform.position);
                }
            }

            // Calculate camber for solid axle
            if (geometry.isSolid)
            {
                // Center point of imaginary axle
                Vector3 position  = (leftWheel.WheelController.springTravelPoint + rightWheel.WheelController.springTravelPoint) / 2f;
                Vector3 direction = position - leftWheel.WheelController.springTravelPoint;

                // Calculate camber from the mid point
                float camberAngle = VehicleController.AngleSigned(vc.transform.right, direction, vc.transform.forward);
                camberAngle = Mathf.Clamp(camberAngle, -25f, 25f);

                // Set camber
                leftWheel.WheelController.SetCamber(camberAngle);
                rightWheel.WheelController.SetCamber(-camberAngle);
                geometry.camberAtBottom = geometry.camberAtTop = camberAngle;
            }
        }
Beispiel #3
0
        public void Update(VehicleController vc)
        {
            // Drift assist
            if (intensity > 0)
            {
                Vector3 normVel    = vc.vehicleRigidbody.velocity.normalized;
                Vector3 vehicleDir = vc.transform.forward;
                float   driftAngle = VehicleController.AngleSigned(normVel, vehicleDir, vc.transform.up);
                driftAngle = Mathf.Sign(driftAngle) * Mathf.Clamp(Mathf.Abs(Mathf.Clamp(driftAngle, -90f, 90f)), 0f, Mathf.Infinity);

                if (vc.axles.Count > 0)
                {
                    Axle    a        = vc.axles[vc.axles.Count - 1];
                    Vector3 center   = (a.leftWheel.ControllerTransform.position + a.rightWheel.ControllerTransform.position) / 2f;
                    float   forceMag = driftAngle * Mathf.Lerp(0f, vc.vehicleRigidbody.mass, vc.Speed / 15f) * intensity;
                    Vector3 force    = vc.transform.right * forceMag;
                    vc.vehicleRigidbody.AddForceAtPosition(force, center);
                }
            }
        }