Exemplo n.º 1
5
    //Grab visual wheel and apply transform
    void ApplyLocalPositionToVisualWheel(WheelCollider collider)
    {
        if (collider.transform.childCount == 0)
            return;

        Transform visWheel = collider.transform.GetChild (0);

        Vector3 position; //= collider.transform.localPosition;
        Quaternion rotation;// = collider.transform.localRotation;
        collider.GetWorldPose (out position, out rotation);

        visWheel.transform.position = position;//collider.transform.parent.TransformPoint (position);
        visWheel.transform.rotation = rotation;//collider.transform.parent.rotation * rotation;
    }
Exemplo n.º 2
1
    // Update is called once per frame
    void FixedUpdate()
    {
        WheelL = GameObject.Find("WheelFL").GetComponent<WheelCollider>();
        WheelR = GameObject.Find("WheelFR").GetComponent<WheelCollider>();

        WheelHit hit;
        float travelL = 1.0f;
        float travelR = 1.0f;

        bool GroundedL = WheelL.GetGroundHit(out hit);
        if (GroundedL)
        {
            travelL = (-WheelL.transform.InverseTransformPoint(hit.point).y - WheelL.radius) / WheelL.suspensionDistance;
        }
        bool GroundedR = WheelR.GetGroundHit(out hit);
        if (GroundedR)
        {
            travelR = (-WheelR.transform.InverseTransformPoint(hit.point).y - WheelR.radius) / WheelR.suspensionDistance;
        }
        float antiRollForce = (travelL - travelR) * antiRoll;

        if (GroundedL)
        {
            rb.AddForceAtPosition(WheelL.transform.up * -antiRollForce, WheelL.transform.position);
        }
        if (GroundedR)
        {
            rb.AddForceAtPosition(WheelR.transform.up * antiRollForce, WheelR.transform.position);
        }
    }
Exemplo n.º 3
1
 public VehicleWheel(  WheelCollider vehicleWheel,
                       WheelComponent wheelComponent,
                       WheelPosition frontRear,
                       WheelPosition leftRight )
 {
     wheelFrontRear = frontRear;
     wheelLeftRight = leftRight;
     checkCurrentWheelState = WheelsOnGround.WHEEL_ON_GROUND;
     mainWheelCollider = vehicleWheel;
     wheelPhysicsComponent = wheelComponent;
     visualWheel = vehicleWheel.GetComponentInChildren<MeshRenderer>( ).transform;
     wheelRadius = ( visualWheel.GetComponent<Renderer>().bounds.size.y / 2 );
     mainWheelCollider.radius = wheelRadius;
     mainWheelCollider.GetGroundHit( out wheelGroundContactPoint );
 }
Exemplo n.º 4
1
    private void AntiRoll(WheelCollider leftWheel, WheelCollider rightWheel)
    {
        var AntiRoll = 5000f;

        WheelHit hit;
        var travelL = 1.0f;
        var travelR = 1.0f;

        var groundedL = leftWheel.GetGroundHit(out hit);
        if (groundedL)
            travelL = (-leftWheel.transform.InverseTransformPoint(hit.point).y - leftWheel.radius) / leftWheel.suspensionDistance;

        var groundedR = rightWheel.GetGroundHit(out hit);
        if (groundedR)
            travelR = (-rightWheel.transform.InverseTransformPoint(hit.point).y - rightWheel.radius) / rightWheel.suspensionDistance;

        var antiRollForce = (travelL - travelR) * AntiRoll;

        if (groundedL)
            rBody.AddForceAtPosition(leftWheel.transform.up * -antiRollForce, leftWheel.transform.position);
        if (groundedR)
            rBody.AddForceAtPosition(rightWheel.transform.up * antiRollForce, rightWheel.transform.position);
    }
Exemplo n.º 5
0
    void Awake()
    {
        o_Wheel_L1 = GameObject.Find ("o_Wheel_L1");
        c_Wheel_L1 = GameObject.Find ("c_Wheel_L1").GetComponent<WheelCollider> ();

        o_Wheel_L2 = GameObject.Find ("o_Wheel_L2");
        c_Wheel_L2 = GameObject.Find ("c_Wheel_L2").GetComponent<WheelCollider> ();

        o_Wheel_R1 = GameObject.Find ("o_Wheel_R1");
        c_Wheel_R1 = GameObject.Find ("c_Wheel_R1").GetComponent<WheelCollider> ();

        o_Wheel_R2 = GameObject.Find ("o_Wheel_R2");
        c_Wheel_R2 = GameObject.Find ("c_Wheel_R2").GetComponent<WheelCollider> ();

        carRigidBody = GetComponent<Rigidbody> ();
        Vector3 center_of_mass = carRigidBody.centerOfMass;
        center_of_mass = center_of_mass + (-1.0f * transform.up.normalized) * 2.0f;

        GameObject obj = GameObject.FindGameObjectWithTag ("RacingGUIText");
        goalText = obj.GetComponent<Text>();

        foreach (AudioSource s in GetComponents<AudioSource> ()) {
            if (s.clip.name == "pick_up") {
                pickup_Sound = s;
            }

            if (s.clip.name == "engine_low") {
                engineSound = s;
            }
        }
        engineSound = GetComponent<AudioSource> ();

        startPos = transform.position;
        startRot = transform.rotation;
    }
 public FSBDWheelClass(WheelCollider _wheelCollider, Transform _wheelMesh, Transform _suspensionParent)
 {
     wheelCollider = _wheelCollider;
     wheelMesh = _wheelMesh;
     suspensionParent = _suspensionParent;
     setupFxLocation();
 }
Exemplo n.º 7
0
 // Use this for initialization
 void Start()
 {
     _wheel = GetComponent<WheelCollider>();
     //bikerhealth = transform.parent.Find( "bodyHealthTrigger" ).GetComponent<Health>();
     bikerhealth = transform.parent.GetComponentInChildren<Health>();
     bikerscore = transform.parent.GetComponent<Score>();
 }
Exemplo n.º 8
0
 void updateColliders(WheelCollider[] colliders, float forwardStiffness, float sidewaysStiffness)
 {
     foreach (WheelCollider collider in colliders) {
         collider.forwardFriction = cloneCurve(collider.forwardFriction, forwardStiffness);
         collider.sidewaysFriction = cloneCurve(collider.sidewaysFriction, sidewaysStiffness);
     }
 }
Exemplo n.º 9
0
    void Start()
    {
        Physics.gravity = new Vector3(0.0f, -30.0f, 0.0f);
        FL_Wheel = transform.FindChild("fl_col").transform.collider as WheelCollider;
        FR_Wheel = transform.FindChild("fr_col").transform.collider as WheelCollider;
        BL_Wheel = transform.FindChild("rl_col").transform.collider as WheelCollider;
        BR_Wheel = transform.FindChild("rr_col").transform.collider as WheelCollider;

        FL_Pos = transform.FindChild("fl_col").transform;
        FR_Pos = transform.FindChild("fr_col").transform;

        FL_Mesh = transform.FindChild("SUV_wheel_front_left").transform;
        FR_Mesh = transform.FindChild("SUV_wheel_front_right").transform;
        BL_Mesh = transform.FindChild("SUV_wheel_rear_left").transform;
        BR_Mesh = transform.FindChild("SUV_wheel_rear_right").transform;

        rigidbody.centerOfMass = center_of_mass;

        m_targetPos[0] = new Vector3(130.0f,0.0f,145.0f);
        m_targetPos[1] = new Vector3(70.0f, 0.0f, 145.0f);
        m_targetPos[2] = new Vector3(60.0f, 0.0f, 130.0f);
        m_targetPos[3] = new Vector3(70.0f, 0.0f, 110.0f);
        m_targetPos[4] = new Vector3(130.0f, 0.0f, 110.0f);
        m_targetPos[5] = new Vector3(140.0f, 0.0f, 130.0f);
    }
 // Use this for initialization
 void Start()
 {
     collider = GetComponent<WheelCollider>();
     owner = GetComponentInParent<VehicleLogic>();
     foreach (Transform t in transform)
         wheel = t;  //happens only once
 }
Exemplo n.º 11
0
    private float trackRpm; //3

    #endregion Fields

    #region Methods

    public void CalculateMotorForce(WheelCollider col, float accel, float steer,float kiirus,float minuk2ik)
    {
        //6
        WheelFrictionCurve fc = col.sidewaysFriction; //7
        //siin toimub reaalne edasiliikumine ja juhtimine.
        if(accel == 0 && steer == 0)
        { //7
        col.brakeTorque = maxBrakeTorque; //7
        }
        else if(accel == 0.0f)
        { //8
        col.brakeTorque = rotateOnStandBrakeTorque; //9
        col.motorTorque = steer*rotateOnStandTorque; //10
        fc.stiffness = 1.0f + minOnStayStiffness - Mathf.Abs(steer);
        }
        else{ //8
        if(minuk2ik<2f&&kiirus>maxkiirus/2)
        {
        col.brakeTorque = maxBrakeTorque;
        }
        else
        col.brakeTorque = minBrakeTorque; //9
        //Debug.Log("käik:"+minuk2ik);
        if(kiirus<maxkiirus/2)
        {
        col.motorTorque =2* accel*forwardTorque; //10
        }
        else if(kiirus<maxkiirus&&minuk2ik>1f)
        {
        //Debug.Log("tekin");
        col.motorTorque = accel*forwardTorque; //10
        }
        else
        col.motorTorque =0;
        if(steer < 0)
        { //11
        col.brakeTorque = rotateOnMoveBrakeTorque; //12
        col.motorTorque = steer*forwardTorque*rotateOnMoveMultiply;//13
        fc.stiffness = 1.0f + minOnMoveStiffness - Mathf.Abs(steer); //14
        }
        if(steer > 0)
        { //15
        col.motorTorque = steer*forwardTorque*rotateOnMoveMultiply;//16
        fc.stiffness = 1.0f + minOnMoveStiffness - Mathf.Abs(steer); //17
        }
        }
        //ja siin maal on see läbi
        if(fc.stiffness > 1.0f)
        fc.stiffness = 1.0f; //18
        col.sidewaysFriction = fc; //19
        if(col.rpm > 0 && accel < 0)
        { //20
        col.brakeTorque = maxBrakeTorque; //21
        }
        else if(col.rpm < 0 && accel > 0)
        { //22
        col.brakeTorque = maxBrakeTorque; //23
        }
    }
Exemplo n.º 12
0
 void ApplyVisualTransform(WheelCollider wc, Transform mesh)
 {
     Vector3 pos;
     Quaternion rot;
     wc.GetWorldPose(out pos,out rot);
     mesh.position = pos;
     mesh.rotation = rot;
 }
    protected void initialize()
    {
        bumperCar = GetComponent<BumperCarComponent>();

        Transform wheelColliders = transform.FindChild("WheelColliders");
        wheelRearRight = wheelColliders.FindChild("WheelRearRight").GetComponent<WheelCollider>();
        wheelRearLeft = wheelColliders.FindChild("WheelRearLeft").GetComponent<WheelCollider>();
        wheelFront = wheelColliders.FindChild("WheelFront").GetComponent<WheelCollider>();
    }
    void Start()
    {
        wheel_col = GetComponent<WheelCollider>();
        vehicleRigid = vehicle.GetComponent<Rigidbody>();

        if(FindObjectOfType(typeof(SAICSkidmarks)))
            skidmarks = FindObjectOfType(typeof(SAICSkidmarks)) as SAICSkidmarks;
        else
            Debug.Log("No skidmarks object found. Skidmarks will not be drawn. Drag ''SAICSkidmarksManager'' from Prefabs folder, and drop on to your existing scene...");
    }
Exemplo n.º 15
0
    // Use this for initialization
    void Start()
    {
        // Setting Wheel Collider Variables
        backLeftWheelCollider = ( WheelCollider )gameObject.transform.Find( "Wheels/BackLeftWheel/BackLeftWheelCollider" ).GetComponent( typeof( WheelCollider ) );
        backRightWheelCollider = ( WheelCollider )gameObject.transform.Find( "Wheels/BackRightWheel/BackRightWheelCollider" ).GetComponent( typeof( WheelCollider ) );

        // braketorque acts as a handbrake
        backLeftWheelCollider.brakeTorque = 600.0f;
        backRightWheelCollider.brakeTorque = 600.0f;
    }
Exemplo n.º 16
0
    private WheelData SetupWheels(Transform wheel, WheelCollider col)
    {
        //10
        WheelData result = new WheelData();

        result.wheelTransform = wheel; //10
        result.col = col; //10
        result.wheelStartPos = wheel.transform.localPosition; //10

        return result; //10
    }
Exemplo n.º 17
0
    void Start()
    {
        wheelCollider = GetComponent<WheelCollider>();
        carController = transform.root.GetComponent<SAICSmartAICar>();
        carRigid = carController.GetComponent<Rigidbody>();

        if(FindObjectOfType(typeof(SAICSkidmarks)))
            skidmarks = FindObjectOfType(typeof(SAICSkidmarks)) as SAICSkidmarks;
        else
            Debug.Log("No skidmarks object found. Skidmarks will not be drawn. Drag ''RCCSkidmarksManager'' from Prefabs folder, and drop on to your existing scene...");
    }
Exemplo n.º 18
0
 public void ApplyLocalPositionToVisuals ( WheelCollider wheel )
 {
     if ( wheel.transform.childCount == 0 )
     {
         return;
     }
     //Transform visualWheel = wheel.transform.GetChild( 0 );
     //Vector3 position = new Vector3( 0, 0, 0 );
     //Quaternion rotation = Quaternion.identity;
     //wheel.GetLocalPose( out position, out rotation );
     //visualWheel.transform.position = wheel.transform.parent.TransformPoint( position );
     //visualWheel.transform.rotation = wheel.transform.parent.rotation * rotation;
 }
    // Use this for initialization
    void Start()
    {
        if ( null != WheelRollClip )
        {
            WheelRoll = gameObject.AddComponent<AudioSource>();
            WheelRoll.clip = WheelRollClip;
            WheelRoll.loop = true;
            WheelRoll.volume = 0.0f;
            WheelRoll.Play();
            WheelRoll.dopplerLevel = 0.0f;
        }

        Wheel = gameObject.GetComponent<WheelCollider>();
    }
Exemplo n.º 20
0
    public void ApplyLocalPositionToVisuals(WheelCollider collider)
    {
        if (collider.transform.childCount == 0) {
            return;
        }

        Transform visualWheel = collider.transform.GetChild(0);

        Vector3 position;
        Quaternion rotation;
        collider.GetWorldPose(out position, out rotation);

        visualWheel.transform.position = position;
        visualWheel.transform.rotation = rotation;
    }
Exemplo n.º 21
0
    public void ApplyLocalPositionToVisuals(WheelCollider collider)
    {
        if (collider.transform.childCount == 0)
        {
            return;
        }

        Transform visualWheel = collider.transform.GetChild(0);

        Vector3    position;
        Quaternion rotation;

        collider.GetWorldPose(out position, out rotation);

        visualWheel.transform.position = position;
        visualWheel.transform.rotation = rotation;
    }
Exemplo n.º 22
0
    public float maxSteeringAngle;    // maximum steer angle the wheel can have

    // Finds corresponding visual wheel and correctly applies the transform
    public void ApplyLocalPositionToVisuals(WheelCollider collider)
    {
        if (collider.transform.childCount == 0)
        {
            return;             // return if the wheelcollider has no children
        }

        Transform visualWheel = collider.transform.GetChild(0);          // otherwise, get the first child of the collider

        Vector3    position;
        Quaternion rotation;

        collider.GetWorldPose(out position, out rotation);

        visualWheel.transform.position = position;
        visualWheel.transform.rotation = rotation;
    }
Exemplo n.º 23
0
    public void WheelsRotation(WheelCollider collider)
    {
        if (wheels == null)
        {
            return;
        }
        // 获取旋转信息
        Vector3    position;
        Quaternion rotation;

        collider.GetWorldPose(out position, out rotation);
        // 旋转每个轮子
        foreach (Transform wheel in wheels)
        {
            wheel.rotation = rotation;
        }
    }
Exemplo n.º 24
0
    // Use this for initialization
    void Start()
    {
        rigidbody.isKinematic = true;
        // used for distance calculation using rpm of wheels
        rpmtodist = 2f * Mathf.PI * wheelRadius / 60f;

        // 4 wheels, if needed different size just modify and modify
        // the wheels[...] block below.
        wheels = new WheelData[4];

        // we use 4 wheels, but you can change that easily if neccesary.
        // this is the only place that refers directly to wheelFL, ...
        // so when adding wheels, you need to add the public transforms,
        // adjust the array size, and add the wheels initialisation here.
        wheels[0] = SetWheelParams(wheelFR, maxSteerAngle, JWheelType.Front);
        wheels[1] = SetWheelParams(wheelFL, maxSteerAngle, JWheelType.Front);
        wheels[2] = SetWheelParams(wheelBR, 0.0f, JWheelType.Back);
        wheels[3] = SetWheelParams(wheelBL, 0.0f, JWheelType.Back);

        // found out the hard way: some parameters must be set AFTER all wheel colliders
        // are created, like wheel mass, otherwise your car will act funny and will
        // flip over all the time.
        foreach (WheelData w in wheels)
        {
            WheelCollider col = w.col;
            col.suspensionDistance = suspensionDistance;
            JointSpring js = col.suspensionSpring;
            js.spring            = springs;
            js.damper            = dampers;
            col.suspensionSpring = js;
            col.radius           = wheelRadius;
            col.mass             = wheelWeight;
        }

        // we move the centre of mass (somewhere below the centre works best.)
        rigidbody.centerOfMass += shiftCentre;
        rigidbody.mass          = rigidbody.mass;
        rigidbody.isKinematic   = false;

        // shortcut to audioSource should be engine sound, if null then no engine sound.
        audioSource = (AudioSource)GetComponent(typeof(AudioSource));
        if (audioSource == null)
        {
            Debug.Log("No audio source, add one to the car with looping engine noise (but can be turned off");
        }
    }
        public override void OnEnter()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go != null)
            {
                _wheel = go.GetComponent <WheelCollider>();
            }


            DoIsGrounded();

            if (!everyFrame)
            {
                Finish();
            }
        }
Exemplo n.º 26
0
    /// <summary>
    /// Visual Transformation of the car wheels.
    /// </summary>
    /// <param name="wheelCollider"></param>
    /// <param name="wheelMesh"></param>
    public void ApplyWheelVisuals(WheelCollider wheelCollider, GameObject wheelMesh)
    {
        Vector3    position;
        Quaternion rotation;

        ///get position and rotation of the WheelCollider
        wheelCollider.GetWorldPose(out position, out rotation);

        ///calculate real rotation of the wheels
        Quaternion realRotation = rotation * Quaternion.Inverse(wheelCollider.transform.parent.rotation) * this.transform.rotation;

        ///set position of the wheel
        wheelMesh.transform.position = position;

        ///set rotation of the wheel
        wheelMesh.transform.rotation = realRotation;
    }
    // finds the corresponding visual wheel
    // correctly applies the transform
    public void ApplyLocalPositionToVisuals(WheelCollider vCollider, Quaternion vInitalRotation)
    {
        if (vCollider.transform.childCount == 0)
        {
            return;
        }

        Transform tVisualWheel = vCollider.transform.GetChild(0);             //Get Wheel Mesh

        Vector3    tPosition;
        Quaternion tRotation;

        vCollider.GetWorldPose(out tPosition, out tRotation);

        tVisualWheel.transform.position = tPosition;
        tVisualWheel.transform.rotation = tRotation * vInitalRotation;
    }
    public void ApplyLocalPositionToVisuals(WheelCollider collider)
    {
        if(collider.transform.childCount == 0){
            return;
        }

        Transform visualWheel = collider.transform.GetChild(0);

        Vector3 position;// = collider.transform.position;
        Quaternion rotation;// = collider.transform.rotation;
        collider.GetWorldPose(out position, out rotation);

        visualWheel.transform.position = position;
        visualWheel.transform.rotation = rotation;
        // Note: since we're hacking this together with z=90 rotated cylinders, rotate by 90 for now
        visualWheel.transform.Rotate(new Vector3(0.0f,0.0f,90.0f));
    }
Exemplo n.º 29
0
    void placeWheelAtCollider(Transform wheel, WheelCollider wheelCollider, bool shouldFlipOnZ)
    {
        var pos = Vector3.zero;
        var rot = Quaternion.identity;

        wheelCollider.GetWorldPose(out pos, out rot);

        wheel.position = pos;
        if (shouldFlipOnZ)
        {
            wheel.rotation = rot * Quaternion.Euler(0, 180, 0);
        }
        else
        {
            wheel.rotation = rot;
        }
    }
Exemplo n.º 30
0
    void PlaceWheelChildren(WheelCollider wheel, Transform model)
    {
        RaycastHit hit;

        // Draw a line form the wheel down.  If it hits the ground, put the wheel model there.
        if (Physics.Raycast(wheel.transform.position, -wheel.transform.up, out hit, wheel.suspensionDistance + wheel.radius))
        {
            wheel.transform.GetChild(0).position = hit.point + wheel.transform.up * wheel.radius;
        }
        else         // Wheel too far from ground.  Place objects at the end of the suspension range instead.
        {
            wheel.transform.GetChild(0).position = wheel.transform.position - (wheel.transform.up * wheel.suspensionDistance);
        }

        // Rotate the wheel model
        model.Rotate(0f, 0f, wheel.rpm / 6f, Space.Self);
    }
Exemplo n.º 31
0
    private void CalcMotorForce(WheelCollider col, float acc, float st)
    {
        WheelFrictionCurve fc = col.sidewaysFriction;

        if (acc == 0 && st == 0)
        {
            col.brakeTorque = maxBrake;
        }
        else if (acc == 0.0f)
        {
            col.brakeTorque = 0;
            col.motorTorque = st * maxAccel;
            fc.stiffness    = 1.0f + minOnStayStiffness - Mathf.Abs(st);
        }
        else
        {
            col.brakeTorque = 0;
            col.motorTorque = acc * maxAccel;
            if (st < 0)
            {
                col.brakeTorque = rotateOnMoveBrakeTorque;
                col.motorTorque = st * maxAccel * rotateOnMoveMultiply;
                fc.stiffness    = 1.0f + minOnMoveStiffness - Mathf.Abs(st);
            }
            if (st > 0)
            {
                col.motorTorque = st * maxAccel * rotateOnMoveMultiply;
                fc.stiffness    = 1.0f + minOnMoveStiffness - Mathf.Abs(st);
            }
        }

        if (fc.stiffness > 1.0f)
        {
            fc.stiffness = 1.0f;
        }
        col.sidewaysFriction = fc;

        if (col.rpm > 0 && acc < 0)
        {
            col.brakeTorque = 0;
        }
        else if (col.rpm < 0 && acc > 0)
        {
            col.brakeTorque = 0;
        }
    }
Exemplo n.º 32
0
        protected virtual void UpdateWheelPose(WheelCollider _collider, Transform _transform, bool leftWheel)
        {
            Vector3    _pos  = _transform.position;
            Quaternion _quat = _transform.rotation;

            _collider.GetWorldPose(out _pos, out _quat);

            _transform.position = _pos;
            if (leftWheel)
            {
                _transform.rotation = _quat * leftWheelRotOffset;
            }
            else
            {
                _transform.rotation = _quat * rightWheelRotOffset;
            }
        }
Exemplo n.º 33
0
    /// <summary>
    /// 旋转轮子
    /// </summary>
    /// <param name="collider"></param>
    private void WheelRotation(WheelCollider collider)
    {
        if (collider == null)
        {
            return;
        }

        Vector3    positon = new Vector3();
        Quaternion rotation;

        collider.GetWorldPose(out positon, out rotation);

        foreach (Transform wheel in wheels)
        {
            wheel.rotation = rotation;
        }
    }
        public override void OnStart(StartState state)
        {
            Log.InitLog();
            if (state == StartState.Editor || state == StartState.None)
            {
                return;
            }

            SetupParticles();
            if (scrapeSparks)
            {
                SetupLight();
            }

            moduleWheel = part.FindModuleImplementing <ModuleWheelBase>();
            if (moduleWheel != null)
            {
                moduleWheelDamage     = part.FindModuleImplementing <ModuleWheelDamage>();
                moduleWheelDeployment = part.FindModuleImplementing <ModuleWheelDeployment>();
                wheelCollider         = moduleWheel.wheelColliderHost.GetComponent <WheelCollider>();
                InvokeRepeating("checkLanding", 0f, 0.5f);
            }

            part.GetComponent <AudioBehaviour>().enabled = true;;

            SetupAudio();

            GameEvents.onGamePause.Add(OnPause);
            GameEvents.onGameUnpause.Add(OnUnpause);

#if DEBUG
            if (useSpheres)
            {
                for (int i = 0; i < spheres.Length; i++)
                {
                    spheres[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    Destroy(spheres[i].GetComponent <Collider>());
                }
                spheres[0].GetComponent <Renderer>().material.color = Color.red;
                spheres[1].GetComponent <Renderer>().material.color = Color.green;
                spheres[3].GetComponent <Renderer>().material.color = Color.yellow;
            }
#endif
            //_sparklauncher = gameObject.AddComponent<SparkLauncher>();
        }
Exemplo n.º 35
0
    private static void CreateWheelCollider(string name, Transform carTrans, Transform child)
    {
        child.gameObject.name = "Wheel_" + name;
        GameObject obj = new GameObject();

        obj.name = "WheelCollider_" + name;
        obj.transform.SetParent(carTrans);
        obj.transform.position = child.position;
        WheelCollider wheelCollider = obj.AddComponent <WheelCollider> ();

        wheelCollider.mass                  = 90f;
        wheelCollider.radius                = 0.5f;
        wheelCollider.wheelDampingRate      = 100000;
        wheelCollider.suspensionDistance    = 0.3f;
        wheelCollider.forceAppPointDistance = 1f;
        wheelCollider.center                = Vector3.zero;

        JointSpring jointSpring = wheelCollider.suspensionSpring;

        jointSpring.spring             = 60000f;
        jointSpring.damper             = 6000f;
        jointSpring.targetPosition     = 0.1f;
        wheelCollider.suspensionSpring = jointSpring;

        WheelFrictionCurve wheelforwardFrictionCurve = wheelCollider.forwardFriction;

        wheelforwardFrictionCurve.extremumSlip   = 0.4f;
        wheelforwardFrictionCurve.extremumValue  = 1f;
        wheelforwardFrictionCurve.asymptoteSlip  = 0.8f;
        wheelforwardFrictionCurve.asymptoteValue = 1f;
        wheelforwardFrictionCurve.stiffness      = 1f;
        wheelCollider.forwardFriction            = wheelforwardFrictionCurve;

        WheelFrictionCurve wheelSideWayFrictionCurve = wheelCollider.sidewaysFriction;

        wheelSideWayFrictionCurve.extremumSlip   = 0.2f;
        wheelSideWayFrictionCurve.extremumValue  = 1f;
        wheelSideWayFrictionCurve.asymptoteSlip  = 0.5f;
        wheelSideWayFrictionCurve.asymptoteValue = 1f;
        wheelSideWayFrictionCurve.stiffness      = 1f;
        wheelCollider.sidewaysFriction           = wheelSideWayFrictionCurve;

        child.SetParent(obj.transform);
        child.localPosition = Vector3.zero;
    }
Exemplo n.º 36
0
 private void Move(WheelCollider leftW, WheelCollider rightW)
 {
     if (throttleInput > 0)
     {
         Accelerate(leftW, rightW);
     }
     else if (throttleInput < 0)
     {
         Brake(leftW, rightW);
     }
     else
     {
         leftW.motorTorque  = 0;
         rightW.motorTorque = 0;
         leftW.brakeTorque  = 0;
         rightW.brakeTorque = 0;
     }
 }
Exemplo n.º 37
0
    void  Start()
    {
        wheelCollider = GetComponent <WheelCollider>();
        carController = GetComponentInParent <RCCCarControllerV2>();
        carRigid      = carController.GetComponent <Rigidbody>();

        if (FindObjectOfType(typeof(RCCSkidmarks)))
        {
            skidmarks = FindObjectOfType(typeof(RCCSkidmarks)) as RCCSkidmarks;
        }
        else
        {
            Debug.Log("No skidmarks object found. Skidmarks will not be drawn. Drag ''RCCSkidmarksManager'' from Prefabs folder, and drop on to your existing scene...");
        }

        forwardFrictionCurve  = GetComponent <WheelCollider>().forwardFriction;
        sidewaysFrictionCurve = GetComponent <WheelCollider>().sidewaysFriction;
    }
Exemplo n.º 38
0
        void EasySuspension(WheelCollider wc)
        {
            JointSpring spring = wc.suspensionSpring;

            spring.spring       = Mathf.Pow(Mathf.Sqrt(wc.sprungMass) * naturalFrequency, 2);
            spring.damper       = 2 * dampingRatio * Mathf.Sqrt(spring.spring * wc.sprungMass);
            wc.suspensionSpring = spring;
            Vector3 wheelRelativeBody = transform.InverseTransformPoint(wc.transform.position);
            float   distance          = attachedRigidbody.centerOfMass.y - wheelRelativeBody.y + wc.radius;

            wc.forceAppPointDistance = distance - forceShift;

            // the following line makes sure the spring force at maximum droop is exactly zero
            if (spring.targetPosition > 0 && setSuspensionDistance)
            {
                wc.suspensionDistance = wc.sprungMass * Physics.gravity.magnitude / (spring.targetPosition * spring.spring);
            }
        }
Exemplo n.º 39
0
    private WheelCollider wheel_col;    //To hold self wheel collider


    void Start()
    {
        Debug.LogWarning("Wheel Skidmarks has not been ported to the new PhysX system");
        return;

        //Get the Wheel Collider attached to self
        skidCaller = transform.root.gameObject;
        wheel_col  = GetComponent <WheelCollider>();
        //find object "Skidmarks" from the game
        if (FindObjectOfType <Skidmarks>())
        {
            skidmarks = FindObjectOfType(typeof(Skidmarks)) as Skidmarks;
        }
        else
        {
            Debug.Log("No skidmarks object found. Skidmarks will not be drawn");
        }
    }
Exemplo n.º 40
0
        private void Start()
        {
            skidParticles = transform.root.GetComponentInChildren <ParticleSystem>();

            if (skidParticles != null)
            {
                skidParticles.Stop();
            }

            m_WheelCollider = GetComponent <WheelCollider>();
            m_AudioSource   = GetComponent <AudioSource>();
            PlayingAudio    = false;

            if (skidTrailsDetachedParent == null)
            {
                skidTrailsDetachedParent = new GameObject("Skid Trails - Detached").transform;
            }
        }
Exemplo n.º 41
0
    private void Start()
    {
        nxtInt = 1;
        GameObject detector = Instantiate(new GameObject());

        detector.transform.position = transform.position;
        detector.transform.rotation = transform.rotation;
        detector.transform.parent   = transform;
        detector.name = "Detector";
        detector.AddComponent <Detector>();

        targets            = FindObjectOfType <TrackTargets>();
        wheels             = GetComponentsInChildren <WheelCollider>();
        wheel1             = transform.Find("wheelF1").GetComponent <WheelCollider>();
        wheel2             = transform.Find("wheelF2").GetComponent <WheelCollider>();
        trackPositions     = targets.GetComponentsInChildren <Transform>();
        currentDestination = trackPositions[1]; //trackPositions[0] is the parent holding the track objects. don't use it.
    }
Exemplo n.º 42
0
    public float markWidth = 0.275f;    // The width of the skidmarks. Should match the width of the wheel that it is used for. In meters.

    void Start()
    {
        if (!carParent)
        {
            carParent = GetComponentInParent <Rigidbody> ();
        }

        wheel_col = GetComponent <WheelCollider> ();

        if (FindObjectOfType <Skidmarks>())
        {
            skidmarks = FindObjectOfType <Skidmarks>();
        }
        else
        {
            Debug.Log("No skidmarks object found. Skidmarks will not be drawn");
        }
    }
Exemplo n.º 43
0
    private void StabilizeWheels(WheelCollider leftW, WheelCollider rightW)
    {
        float antiRollForce;

        float rightSuspension = CalculateWheelSuspension(rightW);
        float leftSuspension  = CalculateWheelSuspension(leftW);

        antiRollForce = (leftSuspension - rightSuspension) * antiRollValue;

        if (leftW.isGrounded)
        {
            rb.AddForceAtPosition(leftW.transform.up * -antiRollForce, leftW.transform.position);
        }
        if (rightW.isGrounded)
        {
            rb.AddForceAtPosition(rightW.transform.up * antiRollForce, rightW.transform.position);
        }
    }
Exemplo n.º 44
0
    // finds the corresponding visual wheel
    // correctly applies the transform
    public void ApplyLocalPositionToVisuals(WheelCollider collider, float steering)
    {
        if (collider.transform.childCount == 0)
        {
            return;
        }

        Transform visualWheel = collider.transform.GetChild(0);

        Vector3    position;
        Quaternion r;

        collider.GetWorldPose(out position, out r);

        visualWheel.transform.position = position;
        visualWheel.transform.rotation = r;
        //Quaternion.AngleAxis(steering * Input.GetAxis("Horizontal"), Vector3.forward);
    }
Exemplo n.º 45
0
    private void EnableGrassParticles(WheelCollider wheel, ParticleSystem grassParticles)
    {
        WheelHit hit;

        if (wheel.GetGroundHit(out hit))
        {
            if (hit.collider.name == "Grass" && verticalInput > 0)
            {
                if (!grassParticles.isPlaying)
                {
                    grassParticles.Play();
                }
                return;
            }
        }

        grassParticles.Stop();
    }
Exemplo n.º 46
0
    private void Awake()
    {
        _frontLeftWheelDefaultRotation  = frontLeftWheel.localRotation;
        _frontRightWheelDefaultRotation = frontRightWheel.localRotation;
        _backLeftWheelDefaultRotation   = backLeftWheel.localRotation;
        _backRightWheelDefaultRotation  = backRightWheel.localRotation;

        _frontLeftWheelCollider  = frontLeftWheel.GetComponent <WheelCollider>();
        _frontRightWheelCollider = frontRightWheel.GetComponent <WheelCollider>();
        _backLeftWheelCollider   = backLeftWheel.GetComponent <WheelCollider>();
        _backRightWheelCollider  = backRightWheel.GetComponent <WheelCollider>();

        _wheelColliders    = new WheelCollider[4];
        _wheelColliders[0] = _frontLeftWheelCollider;
        _wheelColliders[1] = _frontRightWheelCollider;
        _wheelColliders[2] = _backLeftWheelCollider;
        _wheelColliders[3] = _backRightWheelCollider;
    }
Exemplo n.º 47
0
    private void rotateWheel(Transform wheel_t, WheelCollider wheel_col, float of)
    {
        /*
         * Method to rotate wheel.
         */
        int   perMin    = 60;
        int   degPerRot = 360;
        float spinAmt   = wheel_col.rpm
                          / (degPerRot * perMin * Time.deltaTime);



        wheel_t.localEulerAngles = new Vector3(wheel_t.localEulerAngles.x, 0.25f * wheel_col.steerAngle - wheel_t.localEulerAngles.z, wheel_t.localEulerAngles.z);

        wheel_t.Rotate(this.transform.worldToLocalMatrix * this.transform.right, spinAmt, Space.Self);
        //wheel_t.RotateAroundLocal(wheel_t.right, spinAmt);
        //wheel_t.RotateAround(wheel_t.transform.worldToLocalMatrix * wheel_t.right, spinAmt);
    }
Exemplo n.º 48
0
    void Start()
    {
        GetComponent <Rigidbody>().centerOfMass = new Vector3(0f, -0.9f, 0.2f); //Valeur initiale assez stable

        FL = GameObject.Find("FL.Col").GetComponent <WheelCollider>();
        FR = GameObject.Find("FR.Col").GetComponent <WheelCollider>();
        RL = GameObject.Find("RL.Col").GetComponent <WheelCollider>();
        RR = GameObject.Find("RR.Col").GetComponent <WheelCollider>();

        COM = GameObject.Find("Col");
        GetComponent <Rigidbody>().centerOfMass = new Vector3(COM.transform.localPosition.x * transform.localScale.x, COM.transform.localPosition.y * transform.localScale.y, COM.transform.localPosition.z * transform.localScale.z);

        for (int i = 1; i <= 16; ++i)
        {
            CarSound.Add(GameObject.Find(string.Format("CarSound ({0})", i)).GetComponent <AudioSource>());
            CarSound[i - 1].Play();
        }
    }
Exemplo n.º 49
0
    void manageSuspensionAndRotation(WheelCollider collider, Transform transform)
    {
        transform.Rotate(0, 0, -collider.rpm / 60F * 360F * Time.deltaTime);

        RaycastHit hit;

        Vector3 colliderCenter = collider.transform.TransformPoint(collider.center);
        Vector3 colliderDirection = collider.transform.TransformDirection(-collider.transform.up);

        if (Physics.Raycast(colliderCenter, colliderDirection, out hit, collider.suspensionDistance + collider.radius))
        {
            transform.position = hit.point - colliderDirection * collider.radius;
        }
        else
        {
            transform.position = colliderCenter - collider.transform.up * collider.suspensionDistance;
        }
    }
Exemplo n.º 50
0
    /// <summary>
    /// Update is called once per frame
    /// </summary>
    void Update()
    {
        if (!parked)
        {
            foreach (Wheel wheel in wheels)
            {
                Vector3    pos = Vector3.zero;
                Quaternion rot = Quaternion.identity;

                WheelCollider col = wheel.Object.GetComponent <WheelCollider>();
                Transform     vis = col.transform.GetChild(0);

                col.GetWorldPose(out pos, out rot);
                vis.rotation = rot;
                vis.position = pos;
            }
        }
    }
    private void UpdateWheel(WheelCollider collider_in, Transform trans_in)
    {
        Vector3    OriginPos  = trans_in.position;
        Quaternion OriginQuat = trans_in.rotation;

        //TODO: Set the wheel height to the terrain under it.
        //For now it will set to worldpos?

        //Get new values for the wheels from the world, wtf c sharp why do it like this
        collider_in.GetWorldPose(out OriginPos, out OriginQuat);

        trans_in.position = OriginPos;
        trans_in.rotation = OriginQuat;

        //fix wheel being 90 degress of

        trans_in.rotation *= Quaternion.Euler(0, 0, 90);
    }
Exemplo n.º 52
0
    /// <summary>
    /// "Constructeur" pour initialiser les paramètres de la voiture
    /// </summary>
    protected void StartCar()
    {
        // Création de la liste contenant les noeuds de la map
        Transform[] pathTransforms = path.GetComponentsInChildren <Transform>();
        for (int i = 0; i < pathTransforms.Length; i++)
        {
            if (pathTransforms[i] != path.transform)
            {
                nodes.Add(pathTransforms[i]);
            }
        }

        // Initialisation de la map
        TextAsset file = Resources.Load <TextAsset>("excel");

        string[] lines = file.text.Split('\n');
        for (int i = 0; i < lines.Length; i++)
        {
            string[] columns = lines[i].Split(';');
            for (int j = 0; j < columns.Length; j++)
            {
                nodesTable[i, j] = Convert.ToInt32(columns[j]);
            }
        }

        // Initalisation des attributs inhérents à la voiture
        WheelCollider[] wheelColliders = GetComponentsInChildren <WheelCollider>();
        wheelRL     = wheelColliders[0];
        wheelRR     = wheelColliders[1];
        wheelFL     = wheelColliders[2];
        wheelFR     = wheelColliders[3];
        carRenderer = GetComponentsInChildren <Renderer>()[0];

        // Initialisation de la caméra arrière
        cameraBackCar         = GetComponentsInChildren <Camera>()[0];
        cameraBackCar.enabled = false;

        // Initialisation du canevas affichant le comportement de la voiture
        canvas         = GetComponentsInChildren <Canvas>()[0];
        canvas.enabled = false;
        textCanvas     = canvas.GetComponentsInChildren <Text>()[0];
        buttonCanvas   = canvas.GetComponentsInChildren <Button>()[0];
        buttonCanvas.onClick.AddListener(TaskOnClick);
    }
Exemplo n.º 53
0
 public override void Start()
 {
     base.Start ();
     previousDistenceToCheckPoint = getDistanceToCheckpoint ();
     wrongWayDelayCount = 0;
     timeToShowResult = 0.0f;
     wheel = gameObject.GetComponent<WheelCollider> ();
     handbrake = false;
     syncStartPosition = GetComponent<Rigidbody>().position;
     syncEndPosition = GetComponent<Rigidbody>().position;
     syncStartRotation = GetComponent<Rigidbody>().rotation;
     syncEndRotation = GetComponent<Rigidbody>().rotation;
     flare = turboFlare.GetComponent<ParticleSystem> ();
     core = turboCore.GetComponent<ParticleSystem> ();
     flare.startSize = 2.0f;
     core.startSize = 2.0f;
     turboFlare.SetActive (false);
     turboCore.SetActive (false);
 }
Exemplo n.º 54
0
    private void Start()
    {
        skidParticles = transform.root.GetComponentInChildren<ParticleSystem>();

        if (skidParticles == null)
        {
            Debug.LogWarning(" no particle system found on car to generate smoke particles");
        }
        else
        {
            skidParticles.Stop();
        }

        m_WheelCollider = GetComponent<WheelCollider>();
        m_AudioSource = GetComponent<AudioSource>();
        PlayingAudio = false;

        if (skidTrailsDetachedParent == null)
        {
            skidTrailsDetachedParent = new GameObject("Skid Trails - Detached").transform;
        }
    }
Exemplo n.º 55
0
 // Use this for initialization
 void Start()
 {
     wheelsCollider = gameObject.GetComponent<WheelCollider> ();
 }
Exemplo n.º 56
0
 //// START UND UPDATE METHODEN
 // Use this for initialization
 void Awake()
 {
     wheelCol = GetComponent<WheelCollider>();
 }
Exemplo n.º 57
0
    void SetupWheelCollider( WheelCollider wc, bool isLeft, bool isFront)
    {
        wc.center = new Vector3( (isLeft) ? -.25f : .25f, wc.center.y,  wc.center.z);
        wc.radius = wheelRadius;
        wc.suspensionDistance = suspensionRange;
        wc.mass = rigidbody.mass/20;

        JointSpring js  = wc.suspensionSpring;

        js.spring = (isFront) ? suspensionFrontSpring : suspensionRearSpring;
        js.damper = suspensionDamper;
        js.targetPosition = 0;

        wc.suspensionSpring = js;
        //wc.forwardFriction = wfc;
        //wc.sidewaysFriction = wfc;
    }
    void DoRollBar(WheelCollider wheelL, WheelCollider wheelR)
    {
        WheelHit hit;
        float travelL = 1.0f;
        float travelR = 1.0f;

        bool groundedL = wheelL.GetGroundHit(out hit);
        if (groundedL)
        {
            travelL = (-wheelL.transform.InverseTransformPoint(hit.point).y - wheelL.radius) / wheelL.suspensionDistance;
        }

        bool groundedR = wheelR.GetGroundHit(out hit);
        if (groundedR)
        {
            travelR = (-wheelR.transform.InverseTransformPoint(hit.point).y - wheelR.radius) / wheelR.suspensionDistance;
        }

        float antiRollForce = (travelL - travelR) * antiRoll;

        if (groundedL)
        {
            rb.AddForceAtPosition(wheelL.transform.up * -antiRollForce, wheelL.transform.position);
        }

        if (groundedR)
        {
            rb.AddForceAtPosition(wheelR.transform.up * antiRollForce, wheelR.transform.position);
        }
    }
    void Start()
    {
        car = transform.parent.GetComponent<CarController>();
        followCamera = transform.parent.GetComponent<CarAudio> ().followCamera;
        wheelCollider = collider as WheelCollider;

        if (wheelModel != null)
        {
            originalWheelModelPosition = wheelModel.localPosition;
            //transform.position = wheelModel.position;// - wheelCollider.suspensionDistance*0.5f*transform.up;
        }

        // store initial starting values of wheelCollider
        sidewaysFriction = wheelCollider.sidewaysFriction;
        forwardFriction = wheelCollider.forwardFriction;
        sidewaysStiffness = wheelCollider.sidewaysFriction.stiffness;
        forwardStiffness = wheelCollider.forwardFriction.stiffness;

        // nominal max rpm at Car's top speed (can be more if Car is rolling downhill!)
        MaxRpm = (car.MaxSpeed / (Mathf.PI * wheelCollider.radius * 2)) * 60;

        // get a reference to the particle system for the tire smoke
        rb = wheelCollider.attachedRigidbody;

        if (skidTrailsDetachedParent == null)
        {
            skidTrailsDetachedParent = new GameObject("Skid Trails - Detached").transform;
        }
    }
Exemplo n.º 60
-1
 internal void OnUpdate(WheelCollider wheel)
 {
     Vector3 position;
     Quaternion rotation;
     wheel.GetWorldPose(out position, out rotation);
     this.transform.rotation = rotation;
 }