コード例 #1
0
    private void PullDownTrigger()
    {
        int num = (state != CatapultState.Trigger && state != CatapultState.Wind) ? 3000 : 50;

        release.GetComponent <Rigidbody>().SafeAddForceAtPosition(-body.transform.up * num, springRatchet.position);
        body.SafeAddForceAtPosition(body.transform.up * num, springRatchet.position);
    }
コード例 #2
0
        // -----------------------------------------------------------------------------------
        /// <summary>
        /// Updates the hinge joints that make the cable physics
        /// </summary>
        void UpdateJoints()
        {
            int segments = segmentsProp.intValue;

            // set up the array for hinges
            if (jointsProp.arraySize != segments + 1)
            {
                jointsProp.arraySize = segments + 1;
            }

            // if there was a previous root hinge, remove it
            HingeJoint anchor = jointsProp.GetArrayElementAtIndex(0).objectReferenceValue as HingeJoint;

            if (anchor != null)
            {
                DestroyImmediate(anchor.gameObject);
            }

            // create a root hinge
            anchor = AddHingeJoint("Anchor", target.transform, null, 0);
            HingeJoint joint = anchor;

            joint.axis = points[1] - points[0];
            // create all child hinges
            for (int i = 1; i <= segments; i++)
            {
                Rigidbody connectedRB = joint.GetComponent <Rigidbody>();
                joint      = AddHingeJoint("Joint", anchor.transform, connectedRB, i);
                joint.axis = points[i] - points[i - 1];
            }
            serializedObject.ApplyModifiedProperties();
        }
コード例 #3
0
 /// <inheritdoc />
 protected override void SetUpInternals()
 {
     jointMotor.force = joint.motor.force;
     ProcessAutoDrive(facade.MoveToTargetValue);
     jointRigidbody = joint.GetComponent <Rigidbody>();
     CalculateHingeLocation(facade.HingeLocation);
 }
コード例 #4
0
ファイル: Jump.cs プロジェクト: LSBUGPG/Rope
    IEnumerator JumpSwing()
    {
        swinging = true;
        // jump
        physics.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        yield return(null);

        // wait until we start to fall
        yield return(new WaitUntil(() => physics.velocity.y < 0.0f));

        // create a rope
        HingeJoint rope = Instantiate(ropePrefab, transform.position + Vector3.up * 0.5f, Quaternion.identity);

        rope.axis   = Vector3.forward;
        rope.anchor = rope.transform.InverseTransformPoint(pivot.position);
        HingeJoint joint = gameObject.AddComponent <HingeJoint>();

        joint = GetComponent <HingeJoint>();
        joint.connectedBody = rope.GetComponent <Rigidbody>();
        joint.axis          = Vector3.forward;
        // wait until we let go of the mouse
        yield return(new WaitUntil(() => !Input.GetMouseButton(0)));

        Destroy(joint);
        Destroy(rope.gameObject);
        swinging = false;
    }
コード例 #5
0
 public override void Initialize()
 {
     rbL = jointL.GetComponent <Rigidbody>();
     rbR = jointR.GetComponent <Rigidbody>();
     rbL.maxAngularVelocity = maxSpeed;
     rbR.maxAngularVelocity = maxSpeed;
 }
コード例 #6
0
    public override void AttachHingesAndJoints()
    {
        //Create all the hinges and joints
        HingeJoint BH;
        FixedJoint BF;
        GameObject LHood = car.transform.Find("LHood").gameObject;

        LHoodHinge = LHood.AddComponent <HingeJoint>();
        LHoodHinge.connectedBody = GetComponent <Rigidbody>();
        LHoodHinge.anchor        = new Vector3(0.32f, 0.1f, 0f);
        LHoodHinge.axis          = new Vector3(0, -0.08f, 1);
        LHoodHinge.useLimits     = true;
        JointLimits JL = new JointLimits();

        JL.max                 = -90;
        JL.min                 = 0;
        LHoodHinge.limits      = JL;
        LHoodHinge.breakForce  = 32000;
        LHoodHinge.breakTorque = 32000;
        LHoodHinge.GetComponent <Rigidbody>().mass = 20;

        GameObject RHood = car.transform.Find("RHood").gameObject;

        RHoodHinge = RHood.AddComponent <HingeJoint>();
        RHoodHinge.connectedBody = GetComponent <Rigidbody>();
        RHoodHinge.anchor        = new Vector3(-0.34f, 0.23f, 0f);
        RHoodHinge.axis          = new Vector3(0, -0.08f, -1);
        RHoodHinge.useLimits     = true;
        JointLimits JLRH = new JointLimits();

        JLRH.max               = -90;
        JLRH.min               = 0;
        RHoodHinge.limits      = JLRH;
        RHoodHinge.breakForce  = 1600;
        RHoodHinge.breakTorque = 1600;

        HingeParams HP = new HingeParams
        {
            Anchor = new Vector3(0, 0f, -0.48f),
            Axis   = new Vector3(0, 1, 0),
            Limits = new JointLimits {
                max = 10, min = -60
            }
        };

        partsMap["FLDoor"].Hinges.Add("FLDoor", HP);

        HP = new HingeParams
        {
            Anchor = new Vector3(0, 0f, 0.48f),
            Axis   = new Vector3(0.4f, 1, 0),
            Limits = new JointLimits {
                max = -40, min = 10
            }
        };
        partsMap["RFootplate"].Hinges.Add("RFootplate", HP);

        base.AttachHingesAndJoints();
    }
コード例 #7
0
 private void Awake()
 {
     if (joint == null)
     {
         joint = GetComponent <HingeJoint>();
     }
     body = joint.GetComponent <Rigidbody>();
     invInitialLocalRotation = joint.ReadInitialRotation();
 }
コード例 #8
0
    public void assignPrevious()
    {
        //En el caso de que baje la cadena asigno al joint del eslabon actual el rigidbody del previo
        //y al previo el rigidbody del gameobject auxiliar situado al principio de la cadena

        thisJoint.connectedBody = previos.GetComponent <Rigidbody>();
        previos.connectedBody   = auxRb;
        cc.i--;
    }
コード例 #9
0
    private Vector3 HingeAngVel(HingeJoint hinge)
    {
        Vector3 connectedAngVel = Vector3.zero;

        //if (hinge.connectedBody != null && hinge.connectedBody.TryGetComponent<HingeJoint>(out var connectedHinge))
        if (hinge.connectedBody != null)
        {
            connectedAngVel = hinge.connectedBody.angularVelocity;
        }
        return(hinge.GetComponent <Rigidbody>().angularVelocity - connectedAngVel);
    }
コード例 #10
0
    public static void AddTorque(this HingeJoint joint, float torque)
    {
        Rigidbody body      = joint.GetComponent <Rigidbody>();
        Vector3   worldAxis = body.transform.TransformDirection(joint.axis).normalized;

        body.AddTorqueAtPosition(joint.anchor, worldAxis, torque);
        if (joint.connectedBody)
        {
            joint.connectedBody.AddTorqueAtPosition(joint.connectedAnchor, worldAxis, -torque);
        }
    }
コード例 #11
0
    public override void AttachHingesAndJoints()
    {
        //Create all the hinges and joints
        GameObject LHood = car.transform.Find("Bonnet").gameObject;

        BonnetHinge = LHood.AddComponent <HingeJoint>();
        BonnetHinge.connectedBody = GetComponent <Rigidbody>();
        BonnetHinge.anchor        = new Vector3(0.32f, 0.05f, -0.47f);
        BonnetHinge.axis          = new Vector3(1, 0, 0);
        BonnetHinge.useLimits     = true;
        JointLimits JL = new JointLimits();

        JL.max                  = -50;
        JL.min                  = 0;
        BonnetHinge.limits      = JL;
        BonnetHinge.breakForce  = 32000;
        BonnetHinge.breakTorque = 32000;
        BonnetHinge.GetComponent <Rigidbody>().mass = 20;

        HingeParams HP = new HingeParams
        {
            Anchor = new Vector3(0, 0f, 0.59f),
            Axis   = new Vector3(0, 1, 0),
            Limits = new JointLimits {
                max = 60, min = -10
            }
        };

        partsMap["FLDoor"].Hinges.Add("FLDoor", HP);

        HP = new HingeParams
        {
            Anchor = new Vector3(0, 0f, 0.59f),
            Axis   = new Vector3(0, 1, 0),
            Limits = new JointLimits {
                max = 10, min = -60
            }
        };
        partsMap["FRDoor"].Hinges.Add("FRDoor", HP);

        HP = new HingeParams
        {
            Anchor = new Vector3(0.69f, 0f, 0f),
            Axis   = new Vector3(0, 1, -0.3f),
            Limits = new JointLimits {
                max = 0, min = -100
            }
        };
        partsMap["RBumper"].Hinges.Add("RBumper", HP);

        base.AttachHingesAndJoints();
    }
コード例 #12
0
 public virtual void Load(ItemPhysic.EffectHinge effectHingeData)
 {
     if (effectHingeData != null && hingeJoint != null)
     {
         data = effectHingeData;
         EffectData effectData = Catalog.GetData <EffectData>(effectHingeData.effectId);
         effectInstance = effectData.Spawn(this.transform.position, this.transform.rotation, this.transform, pooled: false);
         effectInstance.SetIntensity(0);
         effectInstance.Play();
         jointRb = hingeJoint.GetComponent <Rigidbody>();
         loaded  = true;
     }
 }
コード例 #13
0
 public SwitchingLanes(Vehicle vehicle, LaneData lane1, LaneData lane2, VehicleData vehicleData, HingeJoint hinge, Rigidbody carBody, int currTargetIndex, float currSpeed)
 {
     this.vehicle         = vehicle;
     this.lane1           = lane1;
     this.lane2           = lane2;
     this.vehicleData     = vehicleData;
     this.hinge           = hinge;
     this.hingeRb         = hinge.GetComponent <Rigidbody>();
     this.carBody         = carBody;
     this.hingeTransform  = hinge.transform;
     this.currTargetIndex = currTargetIndex;
     this.currSpeed       = currSpeed;
 }
コード例 #14
0
        void Start()
        {
            LeftMotor_Direction   = 1;
            RightMotor_Direction  = 1;
            LeftMotor_Percentage  = 30;
            RightMotor_Percentage = 30;

            LeftWheel_Rigidbody  = LeftWheel.GetComponent <Rigidbody>();
            RightWheel_Rigidbody = RightWheel.GetComponent <Rigidbody>();

            Physics.IgnoreLayerCollision(15, 16, true);
            Physics.IgnoreLayerCollision(15, 17, true);
            Physics.IgnoreLayerCollision(16, 17, true);
        }
コード例 #15
0
    public Driving(
        Vehicle vehicle,
        LaneData lane,
        HingeJoint hinge,
        VehicleData vehicleData,
        int currTargetIndex,
        float currSpeed,
        Tuple <ParticleSystem, ParticleSystem> smokeFX)
    {
        //Components
        this.vehicle        = vehicle;
        this.lane           = lane;
        this.hinge          = hinge;
        this.hingeRb        = hinge.GetComponent <Rigidbody>();
        this.hingeTransform = hinge.transform;
        this.vehicleData    = vehicleData;
        this.smokeFX        = smokeFX;

        //Initial values
        this.currTargetIndex = currTargetIndex;
        CurrSpeed            = currSpeed;
    }
コード例 #16
0
    private void MapHingeJoints()
    {
        UnityEngine.Object[] objects = GameObject.FindObjectsOfType(typeof(HingeJoint));
        List <HingeJoint>    hinges  = new List <HingeJoint>();

        foreach (UnityEngine.Object o in objects)
        {
            hinges.Add(o as HingeJoint);
        }

        m_medFE  = FindHingeJoint(hinges, GetComponent <Rigidbody>());
        m_proxFE = FindHingeJoint(hinges, m_medFE.GetComponent <Rigidbody>());
        m_mcpFE  = FindHingeJoint(hinges, m_proxFE.GetComponent <Rigidbody>());
        m_finAA  = FindHingeJoint(hinges, m_mcpFE.GetComponent <Rigidbody>());
        m_wrFE   = FindHingeJoint(hinges, m_finAA.GetComponent <Rigidbody>());
        m_wrDev  = FindHingeJoint(hinges, m_wrFE.GetComponent <Rigidbody>());
        m_wrRot  = FindHingeJoint(hinges, m_wrDev.GetComponent <Rigidbody>());
        m_elbFE  = FindHingeJoint(hinges, m_wrRot.GetComponent <Rigidbody>());
        m_humRot = FindHingeJoint(hinges, m_elbFE.GetComponent <Rigidbody>());
        m_shAA   = FindHingeJoint(hinges, m_humRot.GetComponent <Rigidbody>());
        m_shFE   = FindHingeJoint(hinges, m_shAA.GetComponent <Rigidbody>());
    }
コード例 #17
0
    public void OnDataLoaded()
    {
        this.stepParent = base.transform.Find("StepParent");
        this.endPoint   = base.transform.Find("EndPoint");
        if (this.stepPrefab == null || this.endPoint == null)
        {
            return;
        }
        Vector3 vector    = this.endPoint.position - base.transform.position;
        float   magnitude = vector.magnitude;
        float   f         = magnitude / (this.stepLength + this.stepGap);

        this.steps = new List <Transform>();
        for (int i = 0; i < this.stepParent.childCount; i++)
        {
            Transform child = this.stepParent.GetChild(i);
            this.steps.Add(child);
        }
        int num = this.steps.Count - Mathf.FloorToInt(f);

        if (num > 0)
        {
            for (int j = 0; j < num; j++)
            {
                UnityEngine.Object.DestroyImmediate(this.steps[this.steps.Count - 1].gameObject);
                this.steps.RemoveAt(this.steps.Count - 1);
            }
        }
        int num2 = 0;

        while (this.steps.Count < Mathf.FloorToInt(f) && num2 <= 100)
        {
            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.stepPrefab);
            gameObject.transform.parent = this.stepParent;
            gameObject.name             = string.Format("Step{0:000}", this.steps.Count);
            this.steps.Add(gameObject.transform);
            num2++;
        }
        HingeJoint hingeJoint = null;

        for (int k = 0; k < this.steps.Count; k++)
        {
            this.steps[k].localPosition = Vector3.right * ((float)k * (this.stepLength + this.stepGap) + (this.stepLength + this.stepGap) * 0.5f);
            this.steps[k].localRotation = Quaternion.identity;
            HingeJoint component = this.steps[k].GetComponent <HingeJoint>();
            if (hingeJoint != null)
            {
                component.connectedBody = hingeJoint.GetComponent <Rigidbody>();
            }
            component.autoConfigureConnectedAnchor = true;
            hingeJoint = component;
        }
        Transform transform = base.transform.Find("StepRopeParent");

        if (transform != null)
        {
            UnityEngine.Object.DestroyImmediate(transform.gameObject);
        }
        if (transform == null)
        {
            transform        = new GameObject("StepRopeParent").transform;
            transform.parent = base.transform;
        }
        transform.localPosition = Vector3.zero;
        if (this.stepRopes == null)
        {
            this.stepRopes = new List <GameObject>();
        }
        this.stepRopes.Clear();
        for (int l = 0; l < this.steps.Count + 1; l++)
        {
            GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(this.stepRopePrefab);
            gameObject2.name             = string.Format("StepRope{0:000}", l);
            gameObject2.transform.parent = transform;
            if (l < this.steps.Count)
            {
                gameObject2.transform.position = this.steps[l].position;
            }
            else
            {
                gameObject2.transform.position = this.endPoint.position;
            }
            this.stepRopes.Add(gameObject2);
        }
        for (int m = 0; m < this.stepParent.childCount; m++)
        {
            Transform  child2     = this.stepParent.GetChild(m);
            HingeJoint component2 = child2.GetComponent <HingeJoint>();
            if (component2 && this.stepBreakForces.Count > m)
            {
                component2.breakForce = this.stepBreakForces[m];
                if (this.stepBreakForces[m] < 0.1f)
                {
                    this.isBroken = true;
                }
            }
        }
        Transform  transform2 = this.steps[this.steps.Count - 1];
        HingeJoint component3 = this.endPoint.GetComponent <HingeJoint>();

        component3.connectedBody = transform2.GetComponent <Rigidbody>();
        float d = Mathf.Atan2(vector.y, vector.x) * 57.29578f;

        this.stepParent.localEulerAngles = Vector3.forward * d;
        this.endPoint.position           = transform2.position + transform2.right * (this.stepLength * 0.5f + this.stepGap);
        base.transform.rotation          = Quaternion.identity;
        if (Application.isPlaying)
        {
            foreach (Transform transform3 in this.steps)
            {
                BridgeStep     bridgeStep = transform3.GetComponent <BridgeStep>();
                LevelRigidbody component4 = transform3.GetComponent <LevelRigidbody>();
                if (component4)
                {
                    UnityEngine.Object.DestroyImmediate(component4);
                }
                if (!bridgeStep)
                {
                    bridgeStep = transform3.gameObject.AddComponent <BridgeStep>();
                }
                bridgeStep.Init(false);
            }
            LevelRigidbody component5 = this.endPoint.GetComponent <LevelRigidbody>();
            if (component5)
            {
                UnityEngine.Object.DestroyImmediate(component5);
            }
            BridgeStep bridgeStep2 = this.endPoint.GetComponent <BridgeStep>();
            if (!bridgeStep2)
            {
                bridgeStep2 = this.endPoint.gameObject.AddComponent <BridgeStep>();
            }
            bridgeStep2.Init(true);
        }
        this.SubscribeToJointBreaks();
    }
コード例 #18
0
 void Start()
 {
     audioSource = GetComponent <AudioSource>();
     leftBody    = left.GetComponent <Rigidbody>();
     rightBody   = right.GetComponent <Rigidbody>();
 }
コード例 #19
0
        public void Apply()
        {
            this.isActive     = true;
            this.mix          = 1f;
            this.StartingBone = this.skeleton.FindBone(this.startingBoneName);
            this.RecursivelyCreateBoneProxies(this.StartingBone);
            this.RootRigidbody             = this.boneTable[this.StartingBone].GetComponent <Rigidbody>();
            this.RootRigidbody.isKinematic = this.pinStartBone;
            this.RootRigidbody.mass        = this.rootMass;
            List <Collider> list = new List <Collider>();

            foreach (KeyValuePair <Bone, Transform> pair in this.boneTable)
            {
                Transform ragdollRoot;
                Bone      key       = pair.Key;
                Transform transform = pair.Value;
                list.Add(transform.GetComponent <Collider>());
                if (key == this.StartingBone)
                {
                    this.ragdollRoot = new GameObject("RagdollRoot").transform;
                    this.ragdollRoot.SetParent(base.transform, false);
                    if (key == this.skeleton.RootBone)
                    {
                        this.ragdollRoot.localPosition = new Vector3(key.WorldX, key.WorldY, 0f);
                        this.ragdollRoot.localRotation = Quaternion.Euler(0f, 0f, GetPropagatedRotation(key));
                    }
                    else
                    {
                        this.ragdollRoot.localPosition = new Vector3(key.Parent.WorldX, key.Parent.WorldY, 0f);
                        this.ragdollRoot.localRotation = Quaternion.Euler(0f, 0f, GetPropagatedRotation(key.Parent));
                    }
                    ragdollRoot     = this.ragdollRoot;
                    this.rootOffset = transform.position - base.transform.position;
                }
                else
                {
                    ragdollRoot = this.boneTable[key.Parent];
                }
                Rigidbody component = ragdollRoot.GetComponent <Rigidbody>();
                if (component != null)
                {
                    HingeJoint joint = transform.gameObject.AddComponent <HingeJoint>();
                    joint.connectedBody = component;
                    Vector3 vector = ragdollRoot.InverseTransformPoint(transform.position);
                    vector.x *= 1f;
                    joint.connectedAnchor = vector;
                    joint.axis            = Vector3.forward;
                    joint.GetComponent <Rigidbody>().mass = joint.connectedBody.mass * this.massFalloffFactor;
                    JointLimits limits = new JointLimits {
                        min = -this.rotationLimit,
                        max = this.rotationLimit
                    };
                    joint.limits          = limits;
                    joint.useLimits       = true;
                    joint.enableCollision = this.enableJointCollision;
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    if (i != j)
                    {
                        Physics.IgnoreCollision(list[i], list[j]);
                    }
                }
            }
            SkeletonUtilityBone[] componentsInChildren = base.GetComponentsInChildren <SkeletonUtilityBone>();
            if (componentsInChildren.Length > 0)
            {
                List <string> list2 = new List <string>();
                foreach (SkeletonUtilityBone bone2 in componentsInChildren)
                {
                    if (bone2.mode == SkeletonUtilityBone.Mode.Override)
                    {
                        list2.Add(bone2.gameObject.name);
                        UnityEngine.Object.Destroy(bone2.gameObject);
                    }
                }
                if (list2.Count > 0)
                {
                    string message = "Destroyed Utility Bones: ";
                    for (int j = 0; j < list2.Count; j++)
                    {
                        message = message + list2[j];
                        if (j != (list2.Count - 1))
                        {
                            message = message + ",";
                        }
                    }
                    UnityEngine.Debug.LogWarning(message);
                }
            }
            if (this.disableIK)
            {
                ExposedList <IkConstraint> ikConstraints = this.skeleton.IkConstraints;
                int index = 0;
                int count = ikConstraints.Count;
                while (index < count)
                {
                    ikConstraints.Items[index].mix = 0f;
                    index++;
                }
            }
            if (this.disableOtherConstraints)
            {
                ExposedList <TransformConstraint> transformConstraints = this.skeleton.transformConstraints;
                int index = 0;
                int count = transformConstraints.Count;
                while (index < count)
                {
                    transformConstraints.Items[index].rotateMix    = 0f;
                    transformConstraints.Items[index].scaleMix     = 0f;
                    transformConstraints.Items[index].shearMix     = 0f;
                    transformConstraints.Items[index].translateMix = 0f;
                    index++;
                }
                ExposedList <PathConstraint> pathConstraints = this.skeleton.pathConstraints;
                int num9  = 0;
                int num10 = pathConstraints.Count;
                while (num9 < num10)
                {
                    pathConstraints.Items[num9].rotateMix    = 0f;
                    pathConstraints.Items[num9].translateMix = 0f;
                    num9++;
                }
            }
            this.targetSkeletonComponent.UpdateWorld += new UpdateBonesDelegate(this.UpdateSpineSkeleton);
        }
コード例 #20
0
ファイル: ComponentMotor.cs プロジェクト: xDavidLeon/GGJ20
 private void Awake()
 {
     motorRb = motorJoint.GetComponent <Rigidbody>();
 }
コード例 #21
0
 // update joint target position with the given value
 public void UpdateJointAngle(float jointValue)
 {
     joint.GetComponent <Rigidbody> ().WakeUp();
     targetValue = jointValue;
 }
コード例 #22
0
        public void Apply()
        {
            this.isActive     = true;
            this.mix          = 1f;
            this.StartingBone = this.skeleton.FindBone(this.startingBoneName);
            this.RecursivelyCreateBoneProxies(this.StartingBone);
            this.RootRigidbody             = this.boneTable[this.StartingBone].GetComponent <Rigidbody>();
            this.RootRigidbody.isKinematic = this.pinStartBone;
            this.RootRigidbody.mass        = this.rootMass;
            List <Collider> list = new List <Collider>();

            foreach (KeyValuePair <Bone, Transform> keyValuePair in this.boneTable)
            {
                Bone      key   = keyValuePair.Key;
                Transform value = keyValuePair.Value;
                list.Add(value.GetComponent <Collider>());
                Transform transform;
                if (key == this.StartingBone)
                {
                    this.ragdollRoot = new GameObject("RagdollRoot").transform;
                    this.ragdollRoot.SetParent(base.transform, false);
                    if (key == this.skeleton.RootBone)
                    {
                        this.ragdollRoot.localPosition = new Vector3(key.WorldX, key.WorldY, 0f);
                        this.ragdollRoot.localRotation = Quaternion.Euler(0f, 0f, SkeletonRagdoll.GetPropagatedRotation(key));
                    }
                    else
                    {
                        this.ragdollRoot.localPosition = new Vector3(key.Parent.WorldX, key.Parent.WorldY, 0f);
                        this.ragdollRoot.localRotation = Quaternion.Euler(0f, 0f, SkeletonRagdoll.GetPropagatedRotation(key.Parent));
                    }
                    transform       = this.ragdollRoot;
                    this.rootOffset = value.position - base.transform.position;
                }
                else
                {
                    transform = this.boneTable[key.Parent];
                }
                Rigidbody component = transform.GetComponent <Rigidbody>();
                if (component != null)
                {
                    HingeJoint hingeJoint = value.gameObject.AddComponent <HingeJoint>();
                    hingeJoint.connectedBody = component;
                    Vector3 connectedAnchor = transform.InverseTransformPoint(value.position);
                    connectedAnchor.x         *= 1f;
                    hingeJoint.connectedAnchor = connectedAnchor;
                    hingeJoint.axis            = Vector3.forward;
                    hingeJoint.GetComponent <Rigidbody>().mass = hingeJoint.connectedBody.mass * this.massFalloffFactor;
                    hingeJoint.limits = new JointLimits
                    {
                        min = -this.rotationLimit,
                        max = this.rotationLimit
                    };
                    hingeJoint.useLimits       = true;
                    hingeJoint.enableCollision = this.enableJointCollision;
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    if (i != j)
                    {
                        Physics.IgnoreCollision(list[i], list[j]);
                    }
                }
            }
            SkeletonUtilityBone[] componentsInChildren = base.GetComponentsInChildren <SkeletonUtilityBone>();
            if (componentsInChildren.Length > 0)
            {
                List <string> list2 = new List <string>();
                foreach (SkeletonUtilityBone skeletonUtilityBone in componentsInChildren)
                {
                    if (skeletonUtilityBone.mode == SkeletonUtilityBone.Mode.Override)
                    {
                        list2.Add(skeletonUtilityBone.gameObject.name);
                        UnityEngine.Object.Destroy(skeletonUtilityBone.gameObject);
                    }
                }
                if (list2.Count > 0)
                {
                    string str = "Destroyed Utility Bones: ";
                    for (int l = 0; l < list2.Count; l++)
                    {
                        str += list2[l];
                        if (l != list2.Count - 1)
                        {
                            str += ",";
                        }
                    }
                }
            }
            if (this.disableIK)
            {
                ExposedList <IkConstraint> ikConstraints = this.skeleton.IkConstraints;
                int m     = 0;
                int count = ikConstraints.Count;
                while (m < count)
                {
                    ikConstraints.Items[m].mix = 0f;
                    m++;
                }
            }
            if (this.disableOtherConstraints)
            {
                ExposedList <TransformConstraint> transformConstraints = this.skeleton.transformConstraints;
                int n      = 0;
                int count2 = transformConstraints.Count;
                while (n < count2)
                {
                    transformConstraints.Items[n].rotateMix    = 0f;
                    transformConstraints.Items[n].scaleMix     = 0f;
                    transformConstraints.Items[n].shearMix     = 0f;
                    transformConstraints.Items[n].translateMix = 0f;
                    n++;
                }
                ExposedList <PathConstraint> pathConstraints = this.skeleton.pathConstraints;
                int num    = 0;
                int count3 = pathConstraints.Count;
                while (num < count3)
                {
                    pathConstraints.Items[num].rotateMix    = 0f;
                    pathConstraints.Items[num].translateMix = 0f;
                    num++;
                }
            }
            this.targetSkeletonComponent.UpdateWorld += this.UpdateSpineSkeleton;
        }
コード例 #23
0
ファイル: PendulumManager.cs プロジェクト: M-Schiller/Maroon
    public void Update()
    {
        HingeJoint joint = PendulumWeight.GetComponent <HingeJoint>();

        joint.GetComponent <Rigidbody>().WakeUp();

        if (Input.GetMouseButtonUp(0) && mouseDown)
        {
            Debug.Log("Sending Release action");
            IterationResult res = AssessmentManager.Instance.Send(GameEventBuilder.UseObject("operation", "release"));
            GuiPendulum.ShowFeedback(res.Feedback);

            mouseDown       = false;
            joint.useLimits = false;

            //AssessmentManager.Instance.PrintSummary();
        }
        else if (Input.GetMouseButtonDown(0) || mouseDown)
        {
            if (!mouseDown)
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, 100))
                {
                    if (hit.transform.name == PendulumWeight.name)
                    {
                        mouseDown  = true;
                        mouseStart = Input.mousePosition;
                    }
                    else if (hit.transform.name == Stopwatch.name)
                    {
                        if (Stopwatch.GetComponent <StopWatch>().isRunning)
                        {
                            Stopwatch.SendMessage("SWStop");
                        }
                        else
                        {
                            Stopwatch.SendMessage("SWStart");
                        }
                    }
                    else if (hit.transform.name == SlowMoObject.name)
                    {
                        if (slow)
                        {
                            Time.timeScale = 1.0f;
                            GuiPendulum.ShowFeedback(
                                AssessmentManager.Instance.Send(
                                    GameEventBuilder.UseObject("timelaps", "deactivate")
                                    ).Feedback
                                );
                        }
                        else
                        {
                            Time.timeScale = 0.2f;
                            GuiPendulum.ShowFeedback(
                                AssessmentManager.Instance.Send(
                                    GameEventBuilder.UseObject("timelaps", "activate")
                                    ).Feedback
                                );
                        }

                        Time.fixedDeltaTime = 0.02F * Time.timeScale;
                        slow = !slow;
                    }
                }
            }

            if (mouseDown)
            {
                //relative mouse movement / (scaling factor for easy use)
                var angle = ((mouseStart.x - Input.mousePosition.x) / (ropeLength * 10));
                //Everything above 140 degrees seems to freak out unity enormously, just don't allow it
                angle = Math.Min(Math.Max(-140f, angle), 140f);

                limitHinge(joint, angle);
            }
        }
        else if (Input.GetMouseButtonDown(1))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100))
            {
                if (hit.transform.name == Stopwatch.name)
                {
                    Stopwatch.SendMessage("SWReset");
                }
            }
        }

        if (Input.GetAxis("Mouse ScrollWheel") > 0)
        {
            setRopeLengthRelative(RopeLengthChangeStepSize);
        }
        else if (Input.GetAxis("Mouse ScrollWheel") < 0)
        {
            setRopeLengthRelative(-RopeLengthChangeStepSize);
        }

        checkKeyboardInput();
        assertPosition();

        drawRopeAndAngle();
        adjustWeight();
        setText();
    }