// Add a WheelJoint2D to the wheel contained in the array in a specific position
 public void addWheelJoint2D(int wheelPosition)
 {
     // Add the WheelJoint2D component to the wheel
     WheelJoint2D wheelJoint = gameObject.AddComponent<WheelJoint2D>() as WheelJoint2D;
     // Verify if the wheel has a rigidbody2D.
     if(!wheels[wheelPosition].GetComponent<Rigidbody2D>())
         // Add a rigidbody2D to the wheel.
         wheels[wheelPosition].AddComponent<Rigidbody2D>();
     // Set the rigidbody2D of the car to the wheelJoint2D
     wheelJoint.connectedBody = wheels[wheelPosition].GetComponent<Rigidbody2D>();
     // Create a new JointSuspension2D and set the variables to get a cool and real suspension
     JointSuspension2D suspension = new JointSuspension2D();
     // Set the angle of the suspension to 90 degrees.
     suspension.angle = 90.0f;
     // Set the damping ratio to the configurated option.
     suspension.dampingRatio = wheelOptions.dampingRatio;
     // Set the frequency to the configurated option.
     suspension.frequency = wheelOptions.frequency;
     // Set the JointSuspension created to the WheelJoint2D
     wheelJoint.suspension = suspension;
     // Adjust the anchor to the position of the wheel.
     wheelJoint.anchor = wheels[wheelPosition].transform.localPosition;
     // Set the mass of the rigidbody2D of the wheel
     wheels[wheelPosition].GetComponent<Rigidbody2D>().mass = wheelOptions.mass;
     // Set the gravity scale of the rigidbody2D to the wheel.
     wheels [wheelPosition].GetComponent<Rigidbody2D> ().gravityScale = wheelOptions.gravityScale;
 }
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.JointSuspension2D jointSuspension2D = (UnityEngine.JointSuspension2D)value;
     writer.WriteProperty("dampingRatio", jointSuspension2D.dampingRatio);
     writer.WriteProperty("frequency", jointSuspension2D.frequency);
     writer.WriteProperty("angle", jointSuspension2D.angle);
 }
示例#3
0
    LocomotionComponent AttachLeg(GameObject socket)
    {
        // make WheelJoint2D on Vehicle body
        WheelJoint2D legJoint = gameObject.AddComponent<WheelJoint2D>();
        GameObject l = Instantiate(leg) as GameObject;

        l.transform.parent = transform;
        l.transform.localPosition = socket.transform.localPosition;
        legJoint.connectedBody = l.GetComponent<Rigidbody2D>();
        legJoint.connectedAnchor = l.transform.localPosition;
        legJoint.anchor = socket.transform.localPosition;
        legJoint.useMotor = true;
        JointSuspension2D sus = new JointSuspension2D();
        sus.frequency = 5;
        sus.dampingRatio = 1;
        legJoint.suspension = sus;
        JointMotor2D newMotor = new JointMotor2D();
        newMotor.motorSpeed = -300;
        newMotor.maxMotorTorque = 100;
        legJoint.motor = newMotor;

        SpinningLeg spinleg = l.GetComponent<SpinningLeg>();
        spinleg.SetRefToJoint(legJoint);
        return spinleg;
    }
示例#4
0
 static public int constructor(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.JointSuspension2D o;
         o = new UnityEngine.JointSuspension2D();
         pushValue(l, true);
         pushValue(l, o);
         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
 }
    static public int set_angle(IntPtr l)
    {
        UnityEngine.JointSuspension2D o = (UnityEngine.JointSuspension2D)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.angle = v;
        setBack(l, o);
        return(0);
    }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.JointSuspension2D o;
			o=new UnityEngine.JointSuspension2D();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.JointSuspension2D o;
         o = new UnityEngine.JointSuspension2D();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.JointSuspension2D o;
         o=new UnityEngine.JointSuspension2D();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
示例#9
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.JointSuspension2D o;
         o = new UnityEngine.JointSuspension2D();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
// fields

// properties
    static void WheelJoint2D_suspension(JSVCall vc)
    {
        if (vc.bGet)
        {
            UnityEngine.WheelJoint2D _this = (UnityEngine.WheelJoint2D)vc.csObj;
            var result = _this.suspension;
            JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
        }
        else
        {
            UnityEngine.JointSuspension2D arg0  = (UnityEngine.JointSuspension2D)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            UnityEngine.WheelJoint2D      _this = (UnityEngine.WheelJoint2D)vc.csObj;
            _this.suspension = arg0;
        }
    }
示例#11
0
 static void JointSuspension2D_angle(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.JointSuspension2D _this = (UnityEngine.JointSuspension2D)vc.csObj;
         var result = _this.angle;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.JointSuspension2D _this = (UnityEngine.JointSuspension2D)vc.csObj;
         _this.angle = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.JointSuspension2D jointSuspension2D = new UnityEngine.JointSuspension2D();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "dampingRatio":
                    jointSuspension2D.dampingRatio = reader.ReadProperty <System.Single> ();
                    break;

                case "frequency":
                    jointSuspension2D.frequency = reader.ReadProperty <System.Single> ();
                    break;

                case "angle":
                    jointSuspension2D.angle = reader.ReadProperty <System.Single> ();
                    break;
                }
            }
            return(jointSuspension2D);
        }
        public override void OnEnter()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go != null)
            {
                _wj2d = go.GetComponent<WheelJoint2D>();

                if(_wj2d!=null)
                {
                    _motor = _wj2d.motor;
                    _suspension = _wj2d.suspension;
                }
            }

            SetProperties();

            if(!everyFrame)
            {
                Finish();
            }
        }
 static public int get_angle(IntPtr l)
 {
     UnityEngine.JointSuspension2D o = (UnityEngine.JointSuspension2D)checkSelf(l);
     pushValue(l, o.angle);
     return(1);
 }
示例#15
0
 private extern void INTERNAL_set_suspension(ref JointSuspension2D value);
示例#16
0
 private extern void INTERNAL_get_suspension(out JointSuspension2D value);
示例#17
0
 private extern void INTERNAL_set_suspension(ref JointSuspension2D value);
示例#18
0
 private extern void INTERNAL_get_suspension(out JointSuspension2D value);
示例#19
0
 private extern void set_suspension_Injected(ref JointSuspension2D value);
示例#20
0
 private extern void get_suspension_Injected(out JointSuspension2D ret);
    void loadJsonJoints(JSONNode jsonJoints)
    {
        int JointCount = 0;

        for (int i = 0, numberOfJoints = jsonJoints.Count; i < numberOfJoints; i++){
            JSONNode jsonJoint = jsonJoints[i];
            int jointType = jsonJoint["jointType"].AsInt;

            GameObject bodyA = loadedObjects[jsonJoint["bodyA"].AsInt];
            GameObject bodyB = loadedObjects[jsonJoint["bodyB"].AsInt];

            JSONNode localAnchorA = jsonJoint["localAnchorA"];
            Vector2 anchorA = new Vector2(localAnchorA[0].AsFloat / RATIO, -localAnchorA[1].AsFloat / RATIO);
            JSONNode localAnchorB = jsonJoint["localAnchorB"];
            Vector2 anchorB = new Vector2(localAnchorB[0].AsFloat / RATIO, -localAnchorB[1].AsFloat / RATIO);
            bool collideConnected = jsonJoint["collideConnected"].AsBool;
            string userData = jsonJoint["userData"].Value;

            if (jointType == (int) JointTypes.JOINT_DISTANCE || jointType == (int) JointTypes.JOINT_ROPE){
                DistanceJoint2D joint = bodyA.AddComponent<DistanceJoint2D>();
                joint.connectedBody = bodyB.GetComponent<Rigidbody2D>();
                joint.anchor = anchorA;
                joint.connectedAnchor = anchorB;

                // distance joint
                if (jsonJoint["length"] != null){
                    joint.distance = jsonJoint["length"].AsFloat / RATIO;
                    joint.maxDistanceOnly = true;
                }
                // rope joint
                else if (jsonJoint["maxLength"] != null){
                    joint.distance = jsonJoint["maxLength"].AsFloat / RATIO;
                }

                joint.enableCollision = collideConnected;
                joint.name += '_';
                joint.name += userData.Length > 0 ? userData : "joint" + JointCount++;
            }
            else if (jointType == (int) JointTypes.JOINT_REVOLUTE){
                HingeJoint2D joint = bodyA.AddComponent<HingeJoint2D>();
                joint.connectedBody = bodyB.GetComponent<Rigidbody2D>();
                joint.anchor = anchorA;
                joint.connectedAnchor = anchorB;
                joint.enableCollision = collideConnected;
                joint.name += '_';
                joint.name += userData.Length > 0 ? userData : "joint" + JointCount++;

                // limits are not working properly
                bool enableLimits = jsonJoint["enableLimit"].AsBool;
                float referenceAngle = -jsonJoint["referenceAngle"].AsFloat;
                float angleBetweenBodies = Mathf.Atan2(bodyB.transform.position.y - bodyA.transform.position.y,
                                                      bodyB.transform.position.x - bodyA.transform.position.x) * 180 / Mathf.PI;
                float upperAngle = -jsonJoint["lowerAngle"].AsFloat;
                float lowerAngle = -jsonJoint["upperAngle"].AsFloat;
                bool enableMotor = jsonJoint["enableMotor"].AsBool;
                float motorSpeed = -jsonJoint["motorSpeed"].AsFloat;
                float maxMotorTorque = jsonJoint["maxMotorTorque"].AsFloat;

                joint.useLimits = enableLimits;
                JointAngleLimits2D limits = new JointAngleLimits2D();
                limits.max = angleBetweenBodies + upperAngle;
                limits.min = angleBetweenBodies + lowerAngle;
                joint.limits = limits;
                joint.useMotor = enableMotor;
                JointMotor2D motor = new JointMotor2D();
                motor.maxMotorTorque = maxMotorTorque;
                motor.motorSpeed = motorSpeed;
                joint.motor = motor;
            }
            else if (jointType == (int) JointTypes.JOINT_WHEEL){
                WheelJoint2D joint = bodyA.AddComponent<WheelJoint2D>();
                joint.connectedBody = bodyB.GetComponent<Rigidbody2D>();
                joint.anchor = anchorA;
                joint.connectedAnchor = anchorB;
                joint.enableCollision = collideConnected;
                joint.name += '_';
                joint.name += userData.Length > 0 ? userData : "joint" + JointCount++;

                bool enableMotor = jsonJoint["enableMotor"].AsBool;
                float motorSpeed = -jsonJoint["motorSpeed"].AsFloat;
                float maxMotorTorque = jsonJoint["maxMotorTorque"].AsFloat;
                float dampingRatio = jsonJoint["dampingRatio"].AsFloat;
                float frequency = jsonJoint["frequencyHZ"].AsFloat;
                JSONNode localAxisA = jsonJoint["localAxisA"];
                float angle = Mathf.Atan2(-localAxisA[1].AsFloat, localAxisA[0].AsFloat) * 180 / Mathf.PI;

                joint.useMotor = enableMotor;
                JointMotor2D motor = new JointMotor2D();
                motor.maxMotorTorque = maxMotorTorque;
                motor.motorSpeed = motorSpeed;
                joint.motor = motor;

                JointSuspension2D suspension = new JointSuspension2D();
                suspension.dampingRatio = dampingRatio;
                suspension.frequency = frequency;
                suspension.angle = angle;
                joint.suspension = suspension;
            }
            else if (jointType == (int) JointTypes.JOINT_PRISMATIC){
                SliderJoint2D joint = bodyA.AddComponent<SliderJoint2D>();
                joint.connectedBody = bodyB.GetComponent<Rigidbody2D>();
                joint.anchor = anchorA;
                joint.connectedAnchor = anchorB;
                joint.enableCollision = collideConnected;
                joint.name += '_';
                joint.name += userData.Length > 0 ? userData : "joint" + JointCount++;

                bool enableLimits = jsonJoint["enableLimit"].AsBool;
                float referenceAngle = -jsonJoint["referenceAngle"].AsFloat;
                float upperTranslation = jsonJoint["upperTranslation"].AsFloat / RATIO;
                float lowerTranslation = jsonJoint["lowerTranslation"].AsFloat / RATIO;
                bool enableMotor = jsonJoint["enableMotor"].AsBool;
                float motorSpeed = -jsonJoint["motorSpeed"].AsFloat;
                float maxMotorTorque = jsonJoint["maxMotorTorque"].AsFloat;
                JSONNode localAxisA = jsonJoint["localAxisA"];
                float angle = Mathf.Atan2(-localAxisA[1].AsFloat, localAxisA[0].AsFloat) * 180 / Mathf.PI;

                joint.useLimits = enableLimits;
                JointTranslationLimits2D limits = new JointTranslationLimits2D();
                limits.max = upperTranslation;
                limits.min = lowerTranslation;
                joint.limits = limits;
                joint.useMotor = enableMotor;
                JointMotor2D motor = new JointMotor2D();
                motor.maxMotorTorque = maxMotorTorque;
                motor.motorSpeed = motorSpeed;
                joint.motor = motor;
                joint.angle = angle;
            }
        }
    }
 static public int get_dampingRatio(IntPtr l)
 {
     UnityEngine.JointSuspension2D o = (UnityEngine.JointSuspension2D)checkSelf(l);
     pushValue(l, o.dampingRatio);
     return(1);
 }
 static public int get_frequency(IntPtr l)
 {
     UnityEngine.JointSuspension2D o = (UnityEngine.JointSuspension2D)checkSelf(l);
     pushValue(l, o.frequency);
     return(1);
 }
示例#24
0
 private void INTERNAL_set_suspension(ref JointSuspension2D value)
 {
     throw new NotImplementedException("なにこれ");
 }