コード例 #1
0
    private void Awake()
    {
        _collider = this.GetComponent <BoxCollider>();
        _rb       = this.GetComponent <Rigidbody>();
        _ps       = this.GetComponentInChildren <ParticleSystem>();
        _ps.Stop();
        float com_y = _rb.centerOfMass.y - 1;

        _rb.centerOfMass = new Vector3(_rb.centerOfMass.x, _rb.centerOfMass.y - .5f, _rb.centerOfMass.z);
        for (int i = 0; i < 4; i++)
        {
            _suspensionPoints[i] = new SuspensionPoint();
        }
        UpdateSuspensionPoints();

        if (debuggerTools)
        {
            for (int i = 0; i < _suspensionPoints.Length; i++)
            {
                GameObject debug = Instantiate(suspensionDebug, _suspensionPoints[i].point, Quaternion.Euler(Vector3.zero));
                debug.transform.parent        = this.transform;
                _suspensionPoints[i].debugger = debug.GetComponent <SuspensionDebug>();
                _suspensionPoints[i].debugger.Init();
            }
        }
    }
コード例 #2
0
    private void ApplySuspensionForce(SuspensionPoint suspensionPoint)
    {
        float force = suspensionPoint.CompressionRatio * suspensionStiffness;

        rigidbody.AddForceAtPosition(suspensionPoint.Transform.up * force, suspensionPoint.Transform.position, ForceMode.Force);
    }