Пример #1
0
        private void TryToSet()
        {
            centerOfMass = transform.Find("CenterOfMass");
            parameters   = new Parameters(10.0f, 1.5f, 55.0f, 300.0f);
            if (!bodyCollider)
            {
                Transform bc = transform.Find("BodyCollider");
                if (bc)
                {
                    bodyCollider = bc.gameObject.GetComponent <MeshCollider>();
                    if (!bodyCollider)
                    {
                        bodyCollider = bc.gameObject.AddComponent <MeshCollider>();
                    }
                    bodyCollider.sharedMaterial = (PhysicMaterial)AssetDatabase.LoadAssetAtPath("Assets/WheelSystem/PhysicsMaterials/Body.physicMaterial", typeof(PhysicMaterial));

                    bodyCollider.convex = true;
                    if (bodyCollider.GetComponent <MeshRenderer>())
                    {
                        bodyCollider.GetComponent <MeshRenderer>().enabled = false;
                    }
                }
            }

            foreach (var item in transform.GetComponentsInChildren <Transform>())
            {
                if (!item.name.Contains("Joint") && item.name.Contains("Steering"))
                {
                    steering = item.gameObject.GetComponent <Steering>();
                    if (!steering)
                    {
                        steering = item.gameObject.AddComponent <Steering>();
                    }
                    steeringParameter = steering.parameters;
                    break;
                }
            }
            SetAbsorbers();



            wheelsParameters = new List <Wheel.Parameters>(0);
            wheels           = new List <Wheel>(0);
            foreach (var item in transform.GetComponentsInChildren <Transform>())
            {
                if (!item.name.Contains("Joint") && item.name.Contains("Wheel") && !item.name.Contains("WheelPivot") && !item.name.Contains("WheelTurn"))
                {
                    Wheel wheel = item.gameObject.GetComponent <Wheel>();
                    if (!wheel)
                    {
                        wheel = item.gameObject.AddComponent <Wheel>();
                    }
                    wheels.Add(wheel);
                    wheelsParameters.Add(wheel.parameters);
                }
            }
        }
Пример #2
0
 public void TryToSetBodyFromEditorWindow(Transform centerOfMass, Transform bodyCollider, Parameters bodyParameters, Transform steering, Steering.Parameters steeringParameter)
 {
     if (centerOfMass)
     {
         this.centerOfMass = centerOfMass;
     }
     if (bodyCollider)
     {
         this.bodyCollider        = bodyCollider.gameObject.AddComponent <MeshCollider>();
         this.bodyCollider.convex = true;
         this.bodyCollider.GetComponent <MeshRenderer>().enabled = false;
     }
     this.bodyCollider.sharedMaterial = (PhysicMaterial)AssetDatabase.LoadAssetAtPath("Assets/WheelSystem/PhysicsMaterials/Body.physicMaterial", typeof(PhysicMaterial));
     this.parameters = bodyParameters;
     if (steering)
     {
         this.steering          = steering.gameObject.AddComponent <Steering>();
         this.steeringParameter = steeringParameter;
     }
 }
Пример #3
0
        void Update()
        {
            if (!Application.isPlaying)
            {
                if (parameters.name != name)
                {
                    parameters.name = name;
                }

                body.mass                   = parameters.mass;
                joint.useMotor              = parameters.useMotor;
                joint.connectedBody         = connectedBody;
                bodyCollider.sharedMaterial = parameters.physicMaterial;

                if (oldMaxVelocityMPS != maxVelocityMPS || oldHorsepower != horsepower)
                {
                    oldMaxVelocityMPS    = maxVelocityMPS;
                    oldHorsepower        = horsepower;
                    newtonMeterPerSecond = 746.0f * horsepower;
                    tractionForce        = newtonMeterPerSecond / maxVelocityMPS;

                    joint.motor = new JointMotor()
                    {
                        targetVelocity = (180.0f / Mathf.PI) * velocityMPS / radius, force = tractionForce * radius
                    };
                }

                if (oldParameters != parameters)
                {
                    oldParameters = parameters;
                    CalculateCollider();
                }
                if (steering && steeringOldParameters != steering.parameters)
                {
                    steeringOldParameters = steering.parameters;
                    UpdateSteeringParameters();
                }
            }
        }
Пример #4
0
 protected virtual void OnEnable()
 {
     vehicleBodyParameters = new Vehicle.Parameters(10.0f, 1.5f, 55.0f, 300.0f);
     steeringParameters    = new Steering.Parameters(name, 10000.0f, 50.0f, 5.0f, 30.0f, 20.0f);
     wheelParameters       = new Wheel.Parameters[0];
 }