Example #1
0
 // Use this for initialization
 void Start()
 {
     //moter = joint.motor;
     joint = GetComponent<HingeJoint>();
     moter = new JointMotor();
     moter.force = 3000;
 }
Example #2
0
 // Update is called once per frame
 void Update()
 {
     GameObject grapplepoint = GameObject.FindGameObjectWithTag ("HingePoint");
     joint = grapplepoint.GetComponent<HingeJoint> ();
     joint.connectedBody = GetComponent<Rigidbody> ();
     float a = Camera.main.ScreenToWorldPoint(Input.mousePosition).x;
     float b = Camera.main.ScreenToWorldPoint(Input.mousePosition).y;
     float c = transform.position.z;
     if (Input.GetKeyDown (KeyCode.G)) {
         grappling = !grappling;
     //	Camera.main.orthographic = !Camera.main.orthographic;
         if (grapplepoint != null) {
             //grapplepoint.SetActive(grappling);
         //	joint.breakForce = 0;
         }
     }
     if (Input.GetMouseButtonDown (0) && grappling) {
     //	joint.breakForce = Mathf.Infinity;
         if (grapplepoint != null) {
             DestroyObject(grapplepoint);
         }
         Instantiate(grapplePrefab, new Vector3(a, b, c + 10), Quaternion.identity);
         //new Vector3(grapplepoint.transform.position.x, grapplepoint.transform.position.y, grapplepoint.transform.position.z)
     //	joint.connectedAnchor = new Vector3((5 * a) - 20, (5 * b) - 20, c + 10);
         //Debug.Log("World Space: " + transform.TransformPoint(new Vector3(a, b, c + 10)));
         //Debug.Log("Connected Anchor: " + joint.connectedAnchor);
     }
 }
    void _createJoint()
    {
        if (ParentJoint != null && ParentJoint.GetComponent<Rigidbody> () != null) {
            _jointHandle = gameObject.GetComponent<HingeJoint>();
            if(_jointHandle==null)
                _jointHandle=gameObject.AddComponent<HingeJoint> ();

            _jointHandle.connectedBody=ParentJoint.GetComponent<Rigidbody>();

            _jointHandle.connectedAnchor=transform.localPosition;

            switch(Axis)
            {
            case JointAxis.X:
                _jointHandle.axis=Vector3.left;
                break;
            case JointAxis.Y:
                _jointHandle.axis=Vector3.up;
                break;
            case JointAxis.Z:
                _jointHandle.axis=Vector3.forward;
                break;
            }

        }
    }
        private void InitJoint()
        {
            hj = GetComponent<HingeJoint>();
            if (hj == null)
            {
                hj = gameObject.AddComponent<HingeJoint>();
                hj.useLimits = true;
                hj.anchor = new Vector3(0, -0.5f, 0);
                JointLimits limits = hj.limits;

                // this involves quite some guesswork. It is very hard to find general purpose settings but we can try. The user can still create the hingejoint himself.
                switch (direction)
                {
                    case Direction.x:
                        hj.axis = new Vector3(0, 1, 0);
                        limits.min = -130;
                        break;
                    case Direction.y:
                        hj.axis = new Vector3(0, 0, 1);
                        limits.min = -130;
                        break;
                    case Direction.z:
                        hj.axis = new Vector3(1, 0, 0);
                        limits.min = -130;
                        break;
                }
                hj.limits = limits;
            }
        }
 static public int get_limits(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.HingeJoint self = (UnityEngine.HingeJoint)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.limits);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Example #6
0
 IEnumerator DelayBrekability(HingeJoint hj, float to)
 {
     hj.breakForce = float.PositiveInfinity;
     yield return new WaitForSeconds(1);
     if (hj)
         hj.breakForce = to;
 }
 void setLimits(HingeJoint joint, JointLimits limits)
 {
     limits.min = joint.angle;
     limits.max = joint.angle;
     joint.limits = limits;
     joint.useLimits = true;
 }
Example #8
0
 // Use this for initialization
 void Start()
 {
     hinge = GetComponent<HingeJoint> ();
     moter = new JointMotor ();
     hinge.useMotor = true;
     moter.force = 100000.0f;
 }
Example #9
0
    // Use this for initialization
    void Start()
    {
        _initialAngle = transform.rotation.z;

        _maxAngle = 90f;

        hingey = GetComponent<HingeJoint>();
    }
Example #10
0
    void Awake()
    {
        m_collidersArray = GetComponentsInChildren<BoxCollider>();
        m_hingeJoint = GetComponentInChildren<HingeJoint>();
        m_playerBall = GetComponentInChildren<PlayerBall>().gameObject;

        m_audioSource = GetComponentInChildren<AudioSource>();
        m_audioDirector = FindObjectOfType<AudioDirector>();
    }
Example #11
0
    // Use this for initialization
    void Start()
    {
        //	speed = 10.0f;
        //	rotVec = Vector3.zero;

        hingeJoint = GetComponent<HingeJoint> ();
        moter = new JointMotor ();
        moter.force = 100;
    }
Example #12
0
    private void Start()
    {
        _joint = GetComponent<HingeJoint>();

        if(IsLeftFlipper) {
            Game.Instance.LeftFlippers.Add(this);
        } else {
            Game.Instance.RightFlippers.Add(this);
        }
    }
Example #13
0
    private void Start()
    {
        _thisRb = GetComponent<Rigidbody>();
        _thisHj = GetComponent<HingeJoint>();
        _stickRb = _thisHj.connectedBody;
        _startPosition = transform.position;
        _startRotation = transform.rotation;

        pSlider.GetComponent<Slider>().value = KP;
    }
Example #14
0
	void Start () 
    {
        
        wheel = transform.FindChild("Wheel");
        hookJoint = gameObject.GetComponentInChildren<HingeJoint>();
        hookAnimator = hookJoint.GetComponent<Animator>();
        moveSpeed = Random.Range(1,3);

        SpawnPizza();
        isMoving = true;
	}
Example #15
0
    IEnumerator MotorSpeed()
    {
        yield return new WaitForSeconds(timer);

        m_thisHingeJoint = GetComponent<HingeJoint>();
        JointMotor joint = m_thisHingeJoint.motor;
        joint.targetVelocity = m_HingeJointSpeed;
        m_thisHingeJoint.motor = joint;

        if (timer != m_changeSpeed) timer = m_changeSpeed;
    }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.HingeJoint o;
			o=new UnityEngine.HingeJoint();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
 static public int get_spring(IntPtr l)
 {
     try {
         UnityEngine.HingeJoint self = (UnityEngine.HingeJoint)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.spring);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #18
0
    // Use this for initialization
    void Start()
    {
        hinge = GetComponent<HingeJoint>();

        // オリジナルのヒンジの情報を得る
        originSpring = hinge.spring;

        // 打つ最中のヒンジの情報を作成
        turnedSpring = new JointSpring ();
        turnedSpring.spring = originSpring.spring;
        turnedSpring.damper = originSpring.damper;
        turnedSpring.targetPosition = -60;
    }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.HingeJoint o;
         o=new UnityEngine.HingeJoint();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.HingeJoint o;
         o = new UnityEngine.HingeJoint();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #21
0
        protected override void Awake()
        {
            base.Awake();
            HingeJoint = Rigidbody.gameObject.GetComponent<HingeJoint>();
            this.Rigidbody.maxAngularVelocity = 100f;

            if ((StartRotation != null) && (EndRotation != null))
            {
                //HingeJoint.limits.max = StartRotation.rotation.eulerAngles.;

            }

        }
Example #22
0
    public void Detach(bool makeJoint)
    {
        if (!detached)
        {
            detached = true;
            tr.parent = null;
            rb = gameObject.AddComponent<Rigidbody>();
            rb.mass = mass;
            rb.drag = drag;
            rb.angularDrag = angularDrag;

            if (parentBody)
            {
                parentBody.mass -= mass;
                rb.velocity = parentBody.GetPointVelocity(tr.position);
                rb.angularVelocity = parentBody.angularVelocity;

                //Pick a random hinge joint to use
                if (makeJoint && joints.Length > 0)
                {
                    PartJoint chosenJoint = joints[Random.Range(0, joints.Length)];
                    initialAnchor = chosenJoint.hingeAnchor;
                    displacedAnchor = initialAnchor;

                    hinge = gameObject.AddComponent<HingeJoint>();
                    hinge.autoConfigureConnectedAnchor = false;
                    hinge.connectedBody = parentBody;
                    hinge.anchor = chosenJoint.hingeAnchor;
                    hinge.axis = chosenJoint.hingeAxis;
                    hinge.connectedAnchor = initialPos + chosenJoint.hingeAnchor;
                    hinge.enableCollision = false;
                    hinge.useLimits = chosenJoint.useLimits;

                    JointLimits limits = new JointLimits();
                    limits.min = chosenJoint.minLimit;
                    limits.max = chosenJoint.maxLimit;
                    limits.bounciness = chosenJoint.bounciness;
                    hinge.limits = limits;
                    hinge.useSpring = chosenJoint.useSpring;

                    JointSpring spring = new JointSpring();
                    spring.targetPosition = chosenJoint.springTargetPosition;
                    spring.spring = chosenJoint.springForce;
                    spring.damper = chosenJoint.springDamper;
                    hinge.spring = spring;
                    hinge.breakForce = breakForce;
                    hinge.breakTorque = breakForce;
                }
            }
        }
    }
 //funcao que inicia o script
 // Essa funcao cria um vinculo entre o objeto ligado ao eixo e o objeto
 //dono script por meio do componente hingejoint
 void Start()
 {
     if(ligado_ao_eixo != null){
         this.gameObject.AddComponent<HingeJoint>();
         ligacao = this.GetComponent<HingeJoint>();
         if(ligado_ao_eixo.GetComponent<Rigidbody>() == null) ligado_ao_eixo.AddComponent<Rigidbody>();
         ligacao.connectedBody = ligado_ao_eixo.GetComponent<Rigidbody>(); //define o objeto conectado
         ligacao.useMotor = true;
         ligacao.autoConfigureConnectedAnchor = true;
         ligacao.anchor = new Vector3(0.0f,0.031f,-0.0158f);  //ponto de conexao
         ligacao.axis = new Vector3(0,1,0);                   //eixo de rotacao
         ligacao.motor = new JointMotor();
     }
 }
Example #24
0
 // Use this for initialization
 void Start()
 {
     Debug.Log("Script Started");
     hinge = gameObject.GetComponent<HingeJoint>();
     limitRangeIndex = 0;
     increment = 1;
     delay = 0.01f;
     //Debug.Log("limits.max: " + limits.max + " limits.min: " + limits.min);
     limits = hinge.limits;
     limits.max = limits.min + 1;
     hinge.limits = limits;
     //Debug.Log("limits.max: " + limits.max + " limits.min: " + limits.min);
     //		Debug.Log("End of Start() Method");
 }
 static public int set_spring(IntPtr l)
 {
     try {
         UnityEngine.HingeJoint  self = (UnityEngine.HingeJoint)checkSelf(l);
         UnityEngine.JointSpring v;
         checkValueType(l, 2, out v);
         self.spring = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #26
0
    private void OnCollisionStay(Collision collision)
    {
        foreach (ContactPoint cp in collision.contacts)
        {
            Vector3 position = cp.point;
            Vector3 localPosition = transform.InverseTransformPoint(position);
            if (GetComponent<HingeJoint>() == null)
            {
                HingeJoint h = gameObject.AddComponent<HingeJoint>();
                h.axis = Vector3.up;
                localPosition.y = 0;
                h.anchor = localPosition;
                hj = h;
            } else {

                HingeJoint h = hj;
                Vector3 oldHingePosition = h.anchor;
                Vector3 r = Vector3.Cross(localPosition, oldHingePosition);

                if (Vector3.Dot(r, rotatingAround) > 0)
                {

                    //audio.Play();

                    localPosition.y = 0;

                    if ((h.anchor - localPosition).sqrMagnitude > .25)
                    {
                        if(localPosition.x > 0)
                        {
                            localPosition.x = .3f;
                            if (localPosition.z > 0)
                            {
                                localPosition.z = .5f;
                            } else
                            {
                                localPosition.z = -.5f;
                            }
                        } else
                        {
                            localPosition.x = -.6f;
                            localPosition.z = 0f;
                        }
                        h.anchor = localPosition;
                    }

                }
            }
        }
    }
 static public int set_useLimits(IntPtr l)
 {
     try {
         UnityEngine.HingeJoint self = (UnityEngine.HingeJoint)checkSelf(l);
         bool v;
         checkType(l, 2, out v);
         self.useLimits = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    // Use this for initialization
    void Start()
    {
        _doorHinge = GetComponent<HingeJoint>();
        //		_doorHingeLimits = _doorHinge.limits;

        _doorHinge.useLimits = true;

        EventManager.AddListener((int) GameManagerScript.GameEvents.keyPickedUp, OnKeyPickedUp);
        EventManager.AddListener((int) GameManagerScript.GameEvents.UnlockDoor, OnUnlocked);

        _LockRigidbody = MetalLock.GetComponent<Rigidbody> ();
        _DoorRigidbody = GetComponent<Rigidbody> ();

        _UnlockSound = MetalLock.GetComponent<AudioSource> ();
    }
    static int get_hingeJoint(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Component  obj = (UnityEngine.Component)o;
            UnityEngine.HingeJoint ret = obj.hingeJoint;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index hingeJoint on a nil value" : e.Message));
        }
    }
Example #30
0
    static int get_hingeJoint(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.GameObject obj = (UnityEngine.GameObject)o;
            UnityEngine.HingeJoint ret = obj.hingeJoint;
            ToLua.PushSealed(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index hingeJoint on a nil value"));
        }
    }
Example #31
0
    void Start()
    {
        m_hingeJoint = gameObject.GetComponent<HingeJoint>();
        m_hingeJoint.useMotor = true;
        m_hingeJoint.useLimits = true;
        m_hingeJoint.connectedAnchor = Vector3.zero;

        motor = m_hingeJoint.motor;
        limits = m_hingeJoint.limits;

        motor.force = 75;
        motor.targetVelocity = m_inactiveRotationSpeed;

        limits.min = 0;
        limits.max = Mathf.Max(m_minAngle, m_maxAngle);
        limits.min = Mathf.Min(m_minAngle, m_maxAngle);

        m_hingeJoint.motor = motor;
        m_hingeJoint.limits = limits;
    }
Example #32
0
        protected override void Awake()
        {
            base.Awake();
            this.Rigidbody.maxAngularVelocity = 100f;

            if (HingeJoint == null)
            {
                HingeJoint = Rigidbody.gameObject.GetComponent<HingeJoint>();
            }

            Mid = HingeJoint.transform.localRotation;
            Max = Mid * Quaternion.AngleAxis(HingeJoint.limits.max, HingeJoint.axis);
            Min = Mid * Quaternion.AngleAxis(HingeJoint.limits.min, HingeJoint.axis);
            UseMotor = this.HingeJoint.useMotor;

            if (HingeJoint.useLimits)
            {
                AngleRange = (Mathf.Max(HingeJoint.limits.max, HingeJoint.limits.min) - Mathf.Min(HingeJoint.limits.max, HingeJoint.limits.min));
            }
        }
Example #33
0
    private void GrabObstacle()
    {
        m_Asset.spriteId = m_Asset.GetSpriteIdByName(m_HandGrabbedAssetName);

        if (m_GrabbedObstacleHandle != null && m_GrabbedObstacleJoin == null)
        {
            // Move hand.
            m_GoalHeight = GRABBED_OFFSET;
            StopCoroutine("RaiseHand");
            StartCoroutine("RaiseHand");

            // Setup obstacle.
            Vector3 newPosition = transform.position - (m_GrabbedObstacleHandle.transform.position - m_GrabbedObstacleHandle.m_Obstacle.transform.position);
            newPosition.y = m_GrabbedObstacleHandle.m_Obstacle.transform.position.y;
            m_GrabbedObstacleHandle.m_Obstacle.transform.position = newPosition;

            m_GrabbedObstacleJoin = gameObject.AddComponent<HingeJoint>();
            m_GrabbedObstacleJoin.connectedBody = m_GrabbedObstacleHandle.m_Obstacle.rigidbody;
            m_GrabbedObstacleJoin.anchor = m_GrabbedObstacleHandle.transform.localPosition;
        }
    }
        public override void OnEnter()
        {
            var go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value;
            if (go == null)
            {
                LogWarning("Missing gameObject");
                return;
            }

            _joint = go.GetComponent<HingeJoint>();
            if (_joint == null)
            {
                LogWarning("Missing HingeJoint");
                return;
            }

            DoSetProperties();

            if (!everyFrame)
            {
                Finish();
            }
        }
Example #35
0
	void Awake(){		
		//grab pieces:
		_transform = transform;
		_rigidbody = rigidbody;
		_rigidbody.angularDrag = angularDrag;
		_rigidbody.useGravity = false;
		_joint = hingeJoint;
		_joint.axis = dragAxis;
		_joint.anchor = dragAxis*.5f;
		
		//setup a connected body anchor so movement isn't locked to the world:
		GameObject jointAnchor = new GameObject("JointAnchor");
		jointAnchor.transform.parent = _transform;
		Rigidbody jointAnchorRigidbody = jointAnchor.AddComponent<Rigidbody>();
		jointAnchorRigidbody.isKinematic=true;
		jointAnchorRigidbody.useGravity=false;
		_joint.connectedBody=jointAnchorRigidbody;
		
		//setup motor options:
		JointMotor _jointMotor = _joint.motor;
		_jointMotor.force = motorForce;
		_jointMotor.targetVelocity = motorTargetVelocity;
		_joint.motor = _jointMotor;
	}
    private void Start()
    {
        Debug.Assert(inputAxis != string.Empty);

        //Debug.Assert(kingdom != null);

        maxAngle = Mathf.Clamp(maxAngle, 0f, 90f);
        fireForce = Mathf.Clamp(fireForce, 10f, 500f);
        restoreForce = Mathf.Clamp(restoreForce, 5f, fireForce);

        hinge = GetComponent<HingeJoint>();

        //DO NOT ROTATE THE FLIPPER AROUND X OR Z AXIS!!!!!
        if (counterClockWise)
            hinge.axis = transform.up;
        else
            hinge.axis = -transform.up;

        hinge.useSpring = true;
        var spring = hinge.spring;
        spring.spring = restoreForce;
        spring.targetPosition = idleAngle;
        hinge.spring = spring;
    }
    // Use this for initialization
    void Start()
    {
        exporter = GameObject.Find ("Manager").GetComponent<OctetExporter>();

        data.nodeIdFrom = gameObject.GetComponent<ExportInfo>().id;

        hj = gameObject.GetComponent<HingeJoint>();

        data.nodeIdTO = hj.connectedBody.gameObject.GetComponent<ExportInfo>().id;

        data.axisX = hj.axis.x;
        data.axisY = hj.axis.y;
        data.axisZ = hj.axis.z;

        data.anchorX = hj.anchor.x * transform.localScale.x;
        data.anchorY = hj.anchor.y * transform.localScale.y;
        data.anchorZ = hj.anchor.z * transform.localScale.z;

        data.anchorBX = hj.connectedAnchor.x * hj.connectedBody.transform.localScale.x;
        data.anchorBY = hj.connectedAnchor.y * hj.connectedBody.transform.localScale.y;
        data.anchorBZ = hj.connectedAnchor.z * hj.connectedBody.transform.localScale.z;

        exporter.hingeJoints.Add(data);
    }
 public override void OnEnable() => Component = gameObject.GetComponent <UnityEngine.HingeJoint>();
 /// <summary>
 /// Read the data using the reader.
 /// </summary>
 /// <param name="reader">Reader.</param>
 public override object Read(ISaveGameReader reader)
 {
     UnityEngine.HingeJoint hingeJoint = SaveGameType.CreateComponent <UnityEngine.HingeJoint>();
     ReadInto(hingeJoint, reader);
     return(hingeJoint);
 }