Exemple #1
0
 public void Reset()
 {
     GameObject.Destroy(j.GetComponent <CapsuleCollider>());
     GameObject.Destroy(j);
     _trCam.GetComponent <Rigidbody>().isKinematic = true;
     j = null;
 }
    private void Update()
    {
        if (deliverTo != null)
        {
            if (way)
            {
                helper.LookAt(deliverTo);
                transform.rotation  = Quaternion.Lerp(transform.rotation, helper.rotation, Time.deltaTime * 0.4f);
                transform.position += transform.forward * 0.5f;
            }
            else
            {
                transform.position += -transform.up * 0.2f;
                if (transform.position.y < deliverTo.y - 170)
                {
                    if (container != null)
                    {
                        container.GetComponent <Entity>().additionalData = "";
                    }
                    Destroy(container);
                    way = true;
                }
            }

            if (Vector3.Distance(transform.position, deliverTo) < 10)
            {
                deliverTo = new Vector3(-1000, deliverTo.y + 100, -1000);
                way       = false;
            }
        }
    }
Exemple #3
0
 public void Reset()
 {
     GameObject.Destroy(j.GetComponent <CapsuleCollider>());
     GameObject.Destroy(j);
     _trCam.GetComponent <Rigidbody>().isKinematic = true;
     j = null;
     Road.Instance.RemoveRoofCollider();
 }
Exemple #4
0
        private void Update()
        {
            // Make sure the user pressed the mouse down
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }

            var mainCamera = FindCamera();

            // We need to actually hit an object
            RaycastHit hit = new RaycastHit();

            if (
                !Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition).origin,
                                 mainCamera.ScreenPointToRay(Input.mousePosition).direction, out hit, 100,
                                 Physics.DefaultRaycastLayers))
            {
                return;
            }
            // We need to hit a rigidbody that is not kinematic
            if (!hit.rigidbody || hit.rigidbody.isKinematic || hit.transform.gameObject.tag != "Player")
            {
                return;
            }

            if (!m_SpringJoint)
            {
                var       go   = new GameObject("Rigidbody dragger");
                Rigidbody body = go.AddComponent <Rigidbody>();
                m_SpringJoint    = go.AddComponent <SpringJoint>();
                body.isKinematic = false;
            }

            m_SpringJoint.GetComponent <Rigidbody>().MovePosition(hit.point);
            m_SpringJoint.anchor = Vector3.zero;

            m_SpringJoint.spring        = k_Spring;
            m_SpringJoint.damper        = k_Damper;
            m_SpringJoint.maxDistance   = k_Distance;
            m_SpringJoint.connectedBody = hit.rigidbody;

            StartCoroutine("DragObject", hit.distance);
        }
    void AttachToPincet(PincetBehaviour pincet)
    {
        this.sampleSpring.spring = conSpringStiff;
        sampleSpring.GetComponent <Rigidbody>().drag = this.sampleSpringDrag;


        if (!sampleSpring.connectedBody)
        {
            sampleSpring.connectedBody = pincet.pincetTip.transform.GetComponent <Rigidbody>();
            sample.transform.position += pincet.pincetTip.transform.position - this.transform.position;
        }
    }
 /// <summary>
 /// Change different physics parameters and component variebles for an arm control mode
 /// </summary>
 /// <param name="controlParameters"></param>
 public void ChangeArmControlParameters(ArmControlModeInfo controlParameters)
 {
     // Update armTip's rigidbody constraints
     armTip.GetComponent <Rigidbody>().constraints =
         controlParameters.armTipRigidBodyConstraint |
         RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
     // Update the first arm segment
     jointConnectingBody.GetComponent <Rigidbody>().drag = controlParameters.firstArmSegmentRigidbodyDrag;
     jointConnectingBody.massScale          = controlParameters.firstArmSegmentJointMassScale;
     jointConnectingBody.connectedMassScale = controlParameters.firstArmSegmentJointConnectedMassScale;
     // Update the last arm segment
     lastArmSegment.GetComponent <SpringJoint>().connectedMassScale = controlParameters.lastArmSegmentArmTipJointConnectedMassScale;
     //lastArmSegment.GetComponent<ArmUpdatePhysicsVariebles>().armTipJointMaximumConnectedMassScale = controlParameters.lastArmSegmentMaximumConnectedMassScale;
 }
    void Start()
    {
        #if UNITY_EDITOR
        if (target != null)
        {
            SetTarget(target);
        }
        #endif

        spring = GetComponent <SpringJoint>();

        // Next line ensures that the rigidbody will never sleep, avoiding anchor lock bug
        spring.GetComponent <Rigidbody>().sleepThreshold = 0;
    }
Exemple #8
0
    void SetSpringJoint(SpringJoint springJoint, GameObject connectedGameObject)
    {
        springJoint.connectedBody = connectedGameObject.GetComponent <Rigidbody>();
        SpringJoint prefab = springJoint.gameObject == gameObject ? rootJointPrefab : childJointPrefab;

        springJoint.anchor = prefab.anchor;
        springJoint.autoConfigureConnectedAnchor = prefab.autoConfigureConnectedAnchor;

        var sbc = springJoint.GetComponent <BoxCollider>();

        if (sbc)
        {
            Vector3 anchor = sbc.size / 2;
            anchor.y           = 0;
            anchor.z           = 0;
            springJoint.anchor = anchor;
        }

        var cbc = connectedGameObject.GetComponent <BoxCollider>();

        if (cbc)
        {
            springJoint.autoConfigureConnectedAnchor = false;
            Vector3 anchor = cbc.size / 2;
            anchor.y = 0;
            anchor.z = 0;
            anchor.x = -anchor.x;
            springJoint.connectedAnchor = anchor;
        }

        springJoint.spring      = prefab.spring;
        springJoint.damper      = prefab.damper;
        springJoint.minDistance = prefab.minDistance;
        springJoint.maxDistance = prefab.maxDistance;
        springJoint.tolerance   = prefab.tolerance;
        if (springJoint.gameObject != gameObject)
        {
            springJoint.breakForce = prefab.breakForce * Mathf.Sqrt(Mathf.Sqrt(1f / nodeList.Count));
        }
        else
        {
            springJoint.breakForce = prefab.breakForce;
        }
        springJoint.breakTorque         = prefab.breakTorque;
        springJoint.enableCollision     = prefab.enableCollision;
        springJoint.enablePreprocessing = prefab.enablePreprocessing;
        springJoint.massScale           = prefab.massScale;
        springJoint.connectedMassScale  = prefab.connectedMassScale;
    }
    public void Create()
    {
        springForce = spring.spring;
        spring.GetComponent <SpringJoint>().spring = 0;

        spring.GetComponent <Rigidbody>().velocity        = Vector3.zero;
        spring.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;

        spawner.done              = false;
        currentPassenger          = spawner.currentPassenger;
        currentPassengerRigidbody = currentPassenger.GetComponentInChildren <Rigidbody>();
        spawner.currentPassenger  = null;

        /*currentPassenger = GameObject.Instantiate(passengerPrefab, passengerNode);
         * currentPassengerRigidbody = currentPassenger.GetComponentInChildren<Rigidbody>();*/
        currentPassenger.GetComponentInChildren <PassengerController>().catapultController = this;

        // Unparent any non-thrown passenger from the catapult
        if (previousPassenger != null)
        {
            previousPassenger.transform.parent = null;
            previousPassenger = currentPassenger;
        }
    }
Exemple #10
0
    void Start()
    {
        MeshRenderer mr = GetComponent <MeshRenderer>();

        if (mr != null)
        {
            m_SphereSprinMaterial = mr.sharedMaterial;
            Transform parent = this.transform.parent;
            m_RigidBody = parent.GetComponent <Rigidbody>();
            if (m_SpringJoint != null && m_SphereSprinMaterial != null)
            {
                m_SphereSprinMaterial.SetVector("_AnchorPoint_Local", this.transform.InverseTransformPoint(parent.TransformPoint(m_SpringJoint.connectedAnchor)));

                m_LineRenderer = m_SpringJoint.GetComponent <LineRenderer>();
            }
        }
    }
Exemple #11
0
    void CreateJoint()
    {
        SpringJoint sp = MagniteSpell.BlueObj.gameObject.AddComponent <SpringJoint>(); // Создание joint’а

        sp.autoConfigureConnectedAnchor = false;                                       // Чтобы joint всё не сломал, выключаем авто-якоря.
        Vector3 vec = new Vector3(0, 0, 0);

        sp.anchor              = vec;   // Обнуляем наш якорь до центра объекта
        sp.connectedAnchor     = vec;   // Обнуляем якорь объекта-цели до центра
        sp.enableCollision     = true;  // Включаем коллизию между объектами сочленения.
        sp.enablePreprocessing = false; // Может вызвать неприятные дёргания, так что выключаем

        // Скрепливаем первый объект со вторым
        sp.connectedBody = MagniteSpell.RedObj.GetComponent <Rigidbody>();

        EreaseSpell();                   // Очищаем все ссылки на активные объекты
        MagniteSpell.JointList.Add(sp);  // Добавляем ссылку на SpringJoint в лист

        //  Добавляем ссылку на Rigidbody объектов
        Rigidbody rg = sp.GetComponent <Rigidbody>();

        AddRG(sp.connectedBody);
        AddRG(rg);
    }
Exemple #12
0
 // Start is called before the first frame update
 void Start()
 {
     rb.GetComponent <Rigidbody>();
     sJ1.GetComponent <SpringJoint>();
 }
Exemple #13
0
    public void Init(bool LerpToStart)
    {
        FutureFrame = Recrdng.Current.FrameCount - 1;
        //if (_replayer.State == "Playing")
        //{
        //    FutureFrame = Recrdng.Current.CurrFrame + 550;
        //    if (FutureFrame >= Recrdng.Current.FrameCount) FutureFrame = Recrdng.Current.FrameCount - 1;
        //}
        if (_replayer.State == "Playing")
        {
            FutureFrame = Recrdng.Current.CurrFrame + 500;
            if (FutureFrame >= Recrdng.Current.FrameCount)
            {
                FutureFrame = Recrdng.Current.FrameCount - 1;
            }
        }
        if (_replayer.State == "PlayingSloMo")
        {
            FutureFrame = Recrdng.Current.CurrFrame + 250;
            if (FutureFrame >= Recrdng.Current.FrameCount)
            {
                FutureFrame = Recrdng.Current.FrameCount - 1;
            }
        }
        if (_replayer.State == "Reverse")
        {
            FutureFrame = Recrdng.Current.CurrFrame - 550;
            if (FutureFrame < 0)
            {
                FutureFrame = 0;
            }
        }
        Vector3 RandomPos = _car.forward * -3f;

        _prevCarPos = _playerFrames[Recrdng.Current.CurrFrame - 1].Pos;
        Vector3 CarVel = _car.position - _prevCarPos;

        RandomPos       = new Vector3(RandomPos.x, 1, RandomPos.z);
        _trCam.position = _car.position + RandomPos;
        _trCam.LookAt(_car.position);
        _trCam.GetComponent <Camera>().fieldOfView = 60;
        j               = _trCam.gameObject.AddComponent <SpringJoint>();
        j.damper        = 0.9f;
        j.maxDistance   = 5;
        j.connectedBody = _car.GetComponent <Rigidbody>();
        j.GetComponent <Rigidbody>().mass             = 10;
        _trCam.GetComponent <Rigidbody>().isKinematic = false;
        _trCam.GetComponent <Rigidbody>().velocity    = -RandomPos + CarVel * 3;
        CapsuleCollider cc = j.gameObject.AddComponent <CapsuleCollider>();

        cc.radius         = 0.5f;
        cc.height         = 0;
        cc.center         = new Vector3(0, 0.4f, 0);
        cc.sharedMaterial = new PhysicMaterial();
        cc.sharedMaterial.dynamicFriction = 0;
        cc.sharedMaterial.staticFriction  = 0;
        cc.sharedMaterial.bounciness      = 0;
        cc.sharedMaterial.frictionCombine = PhysicMaterialCombine.Minimum;
        //j.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY;
        //j.GetComponent<Rigidbody>().useGravity = true;
        Road.Instance.CreateRoofCollider();
    }
Exemple #14
0
    public void Init(bool LerpToStart)
    {
        float _maxY = 10;

        FutureFrame = Recrdng.Current.FrameCount - 1;    //if replayer stopped
        if (_replayer.State == "Playing")
        {
            FutureFrame = Recrdng.Current.CurrFrame + 500;
            if (FutureFrame >= Recrdng.Current.FrameCount)
            {
                FutureFrame = Recrdng.Current.FrameCount - 1;
            }
            List <List <RecFrameData> > Span = Recrdng.Current.Data.GetRange(Recrdng.Current.CurrFrame, FutureFrame - Recrdng.Current.CurrFrame);
            var SortedSpan = from d
                             in Span
                             orderby d[Recrdng.Current.PlayerCarId].Pos.y
                             select d;
            try { _maxY = SortedSpan.LastOrDefault()[Recrdng.Current.PlayerCarId].Pos.y; } catch { }
        }
        if (_replayer.State == "PlayingSloMo")
        {
            FutureFrame = Recrdng.Current.CurrFrame + 200;
            if (FutureFrame >= Recrdng.Current.FrameCount)
            {
                FutureFrame = Recrdng.Current.FrameCount - 1;
            }
            List <List <RecFrameData> > Span = Recrdng.Current.Data.GetRange(Recrdng.Current.CurrFrame, FutureFrame - Recrdng.Current.CurrFrame);
            var SortedSpan = from d
                             in Span
                             orderby d[Recrdng.Current.PlayerCarId].Pos.y
                             select d;
            try { _maxY = SortedSpan.LastOrDefault()[Recrdng.Current.PlayerCarId].Pos.y; } catch { }
        }
        if (_replayer.State == "Reverse" || _replayer.State == "Rewind")
        {
            FutureFrame = Recrdng.Current.CurrFrame - 500;
            if (FutureFrame < 0)
            {
                FutureFrame = 0;
            }
        }

        Vector3 RandomPos = Random.onUnitSphere * Random.Range(0f, 10f);

        RandomPos       = new Vector3(RandomPos.x, _maxY - _car.position.y + 3, RandomPos.z);
        _trCam.position = _car.position + RandomPos;
        _trCam.LookAt(_car.position);
        _trCam.GetComponent <Camera>().fieldOfView = 60;
        RelPos          = RandomPos;
        j               = _trCam.gameObject.AddComponent <SpringJoint>();
        j.damper        = 0.7f;
        j.maxDistance   = 7;
        j.connectedBody = _car.GetComponent <Rigidbody>();
        j.GetComponent <Rigidbody>().mass             = 10;
        _trCam.GetComponent <Rigidbody>().isKinematic = false;
        CapsuleCollider cc = j.gameObject.AddComponent <CapsuleCollider>();

        cc.radius         = 3;
        cc.height         = 0;
        cc.sharedMaterial = new PhysicMaterial();
        cc.sharedMaterial.dynamicFriction        = 0;
        cc.sharedMaterial.frictionCombine        = PhysicMaterialCombine.Minimum;
        j.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY;
        j.GetComponent <Rigidbody>().useGravity  = false;
    }