Esempio n. 1
0
 public override void Start()
 {
     base.Start();
     this.targetDrive = this.GetComponent <DriveForce>();
     //Get maximum possible RPM
     this.GetMaxRPM();
 }
Esempio n. 2
0
 //Same as previous, but with torqueFactor multiplier for torque
 public void SetDrive(DriveForce from, float torqueFactor)
 {
     this.rpm    = from.rpm;
     this.torque = from.torque * torqueFactor;
     this.curve  = from.curve;
 }
Esempio n. 3
0
 public virtual void Start()
 {
     this.vp          = (VehicleParent)F.GetTopmostParentComponent <VehicleParent>(this.transform);
     this.targetDrive = this.GetComponent <DriveForce>();
     this.newDrive    = this.gameObject.AddComponent <DriveForce>();
 }
Esempio n. 4
0
 public void SetDrive(DriveForce from)
 {
     this.rpm    = from.rpm;
     this.torque = from.torque;
     this.curve  = from.curve;
 }
Esempio n. 5
0
        void Start()
        {
            this.tr = this.transform;
            this.rb = (Rigidbody)F.GetTopmostParentComponent <Rigidbody>(this.tr);
            this.vp = (VehicleParent)F.GetTopmostParentComponent <VehicleParent>(this.tr);
            this.suspensionParent    = this.tr.parent.GetComponent <Suspension.Suspension>();
            this.travelDist          = this.suspensionParent.targetCompression;
            this.canDetach           = this.detachForce < Mathf.Infinity && Application.isPlaying;
            this.initialTirePressure = this.tirePressure;

            if (this.tr.childCount > 0)
            {
                //Get rim
                this.rim = this.tr.GetChild(0);

                //Set up rim glow material
                if (this.rimGlow > 0 && Application.isPlaying)
                {
                    this.rimMat = new Material(this.rim.GetComponent <MeshRenderer>().sharedMaterial);
                    this.rimMat.EnableKeyword("_EMISSION");
                    this.rim.GetComponent <MeshRenderer>().material = this.rimMat;
                }

                //Create detached wheel
                if (this.canDetach)
                {
                    this.detachedWheel           = new GameObject(this.vp.transform.name + "'s Detached Wheel");
                    this.detachedWheel.layer     = LayerMask.NameToLayer("Detachable Part");
                    this.detachFilter            = this.detachedWheel.AddComponent <MeshFilter>();
                    this.detachFilter.sharedMesh = this.rim.GetComponent <MeshFilter>().sharedMesh;
                    var detachRend = this.detachedWheel.AddComponent <MeshRenderer>();
                    detachRend.sharedMaterial = this.rim.GetComponent <MeshRenderer>().sharedMaterial;
                    this.detachedCol          = this.detachedWheel.AddComponent <MeshCollider>();
                    this.detachedCol.convex   = true;
                    this.detachedBody         = this.detachedWheel.AddComponent <Rigidbody>();
                    this.detachedBody.mass    = this.mass;
                }

                //Get tire
                if (this.rim.childCount > 0)
                {
                    this.tire = this.rim.GetChild(0);
                    if (this.deformAmount > 0 && Application.isPlaying)
                    {
                        this.tireMat = new Material(this.tire.GetComponent <MeshRenderer>().sharedMaterial);
                        this.tire.GetComponent <MeshRenderer>().material = this.tireMat;
                    }

                    //Create detached tire
                    if (this.canDetach)
                    {
                        this.detachedTire = new GameObject("Detached Tire");
                        this.detachedTire.transform.parent        = this.detachedWheel.transform;
                        this.detachedTire.transform.localPosition = Vector3.zero;
                        this.detachedTire.transform.localRotation = Quaternion.identity;
                        this.detachTireFilter            = this.detachedTire.AddComponent <MeshFilter>();
                        this.detachTireFilter.sharedMesh = this.tire.GetComponent <MeshFilter>().sharedMesh;
                        var detachTireRend = this.detachedTire.AddComponent <MeshRenderer>();
                        detachTireRend.sharedMaterial = this.tireMat
                                                ? this.tireMat
                                                : this.tire.GetComponent <MeshRenderer>().sharedMaterial;
                    }
                }

                if (Application.isPlaying)
                {
                    //Generate hard collider
                    if (this.generateHardCollider)
                    {
                        var sphereColNew = new GameObject("Rim Collider");
                        sphereColNew.layer             = GlobalControl.ignoreWheelCastLayer;
                        this.sphereColTr               = sphereColNew.transform;
                        this.sphereCol                 = sphereColNew.AddComponent <SphereCollider>();
                        this.sphereColTr.parent        = this.tr;
                        this.sphereColTr.localPosition = Vector3.zero;
                        this.sphereColTr.localRotation = Quaternion.identity;
                        this.sphereCol.radius          = Mathf.Min(this.rimWidth * 0.5f, this.rimRadius * 0.5f);
                        this.sphereCol.material        = GlobalControl.frictionlessMatStatic;
                    }

                    if (this.canDetach)
                    {
                        this.detachedWheel.SetActive(false);
                    }
                }
            }

            this.targetDrive = this.GetComponent <DriveForce>();
            this.currentRPM  = 0;
        }