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.JointSpring o;
         o = new UnityEngine.JointSpring();
         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
 }
Exemplo n.º 2
0
    private void Update()
    {
        _timerAI += Time.deltaTime;
        if(_timerAI > LockAITimer) {
            TriggerAI = false;
        }

        var sj = new JointSpring { spring = 10000, damper = 1 };

        if(IsLeftFlipper) {
            if(Input.GetKeyUp(KeyCode.LeftArrow) || !TriggerUI || (Game.Instance.AIGame && !TriggerAI)) {
                sj.targetPosition = 0;
            }

            if(Input.GetKey(KeyCode.LeftArrow) || TriggerUI || TriggerAI) {
                sj.targetPosition = TargetRotation;
            }

        } else {
            if(Input.GetKeyUp(KeyCode.RightArrow) || !TriggerUI || (Game.Instance.AIGame && !TriggerAI)) {
                sj.targetPosition = 0;
            }

            if(Input.GetKey(KeyCode.RightArrow) || TriggerUI || TriggerAI) {
                sj.targetPosition = -TargetRotation;
            }
        }

        _joint.spring = sj;
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        var spring = new JointSpring();

        spring.spring = FlipperStrength;
        spring.damper = FlipperDamper;

        if ((IsLeftFlipper () && Input.GetKey (KeyCode.A)) || (IsRightFlipper () && Input.GetKey (KeyCode.S)))
        {
            spring.targetPosition = PressedPosition;
        }
        else
        {
            spring.targetPosition = RestPosition;
        }

        HingeJoint.spring = spring;
        HingeJoint.useLimits = true;

        var jointLimits = HingeJoint.limits;
        jointLimits.min = RestPosition;
        jointLimits.max = PressedPosition;

        HingeJoint.limits = jointLimits;
    }
Exemplo n.º 4
0
	void Start () {
		if (vargamchassisbody == null) {
			Debug.LogError("The bike needs a rigidbody to function.");
			enabled = false;
		}
		varwheels = GetComponentsInChildren<WheelCollider>();
		varwheelscount = varwheels.Length;
		for (int varwheelcounter = 0; varwheelcounter < varwheelscount; varwheelcounter++) {
			JointSpring varspring = new JointSpring();
			varspring.spring = cnsspring;
			varspring.damper = cnsdamper;
			varspring.targetPosition = 0;
			varwheels[varwheelcounter].suspensionSpring = varspring;
			varwheels[varwheelcounter].suspensionDistance = cnssuspension;
			
			//full throttle
			varpower = 1;
			varbrake = 0;
		}
		vargamchassisbody.centerOfMass = new Vector3(0, -0.05f, 0);
		varspeedmax = vargamspeedmax * vargamspeedmax;
		varD = transform.root.GetComponentInChildren<clsdismemberator>();
		if (varD != null) {
			varbones = varD.vargamskinnedmeshrenderer.bones;
		}
	}
 /// <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.JointSpring jointSpring = (UnityEngine.JointSpring)value;
     writer.WriteProperty("spring", jointSpring.spring);
     writer.WriteProperty("damper", jointSpring.damper);
     writer.WriteProperty("targetPosition", jointSpring.targetPosition);
 }
Exemplo n.º 6
0
 static public int set_targetPosition(IntPtr l)
 {
     UnityEngine.JointSpring o = (UnityEngine.JointSpring)checkSelf(l);
     System.Single           v;
     checkType(l, 2, out v);
     o.targetPosition = v;
     setBack(l, o);
     return(0);
 }
Exemplo n.º 7
0
 static public int set_damper(IntPtr l)
 {
     UnityEngine.JointSpring o = (UnityEngine.JointSpring)checkSelf(l);
     System.Single           v;
     checkType(l, 2, out v);
     o.damper = v;
     setBack(l, o);
     return(0);
 }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.JointSpring o;
			o=new UnityEngine.JointSpring();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.JointSpring o;
         o = new UnityEngine.JointSpring();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 10
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.JointSpring o;
         o = new UnityEngine.JointSpring();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.JointSpring o;
         o=new UnityEngine.JointSpring();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Exemplo n.º 12
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;
    }
Exemplo n.º 13
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;
                }
            }
        }
    }
 static void HingeJoint_spring(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.HingeJoint _this = (UnityEngine.HingeJoint)vc.csObj;
         var result = _this.spring;
         JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.JointSpring arg0  = (UnityEngine.JointSpring)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
         UnityEngine.HingeJoint  _this = (UnityEngine.HingeJoint)vc.csObj;
         _this.spring = arg0;
     }
 }
Exemplo n.º 15
0
 static void WheelCollider_suspensionSpring(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.WheelCollider _this = (UnityEngine.WheelCollider)vc.csObj;
         var result = _this.suspensionSpring;
         JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.JointSpring   arg0  = (UnityEngine.JointSpring)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
         UnityEngine.WheelCollider _this = (UnityEngine.WheelCollider)vc.csObj;
         _this.suspensionSpring = arg0;
     }
 }
 static void JointSpring_targetPosition(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.JointSpring _this = (UnityEngine.JointSpring)vc.csObj;
         var result = _this.targetPosition;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single           arg0  = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.JointSpring _this = (UnityEngine.JointSpring)vc.csObj;
         _this.targetPosition = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
Exemplo n.º 17
0
    // Update is called once per frame
    void Update()
    {
        JointSpring spring = new JointSpring();
        spring.spring = strength;
        spring.damper = damper;

        if (Input.GetButton(inputButtonName)) {
            Debug.Log(inputButtonName + " Pressed");
            spring.targetPosition = pressedPosition;
        } else {
            spring.targetPosition = restPosition;
        }
        hingeJoint.spring = spring;

        _jointLimits = hingeJoint.limits;
        _jointLimits.min = restPosition;
        _jointLimits.max = pressedPosition;
        _jointLimits.minBounce = 0.02f;
        _jointLimits.maxBounce = 0.02f;
    }
Exemplo n.º 18
0
    // Update is called once per frame
    void Update()
    {
        JointSpring spring = new JointSpring();

        spring.spring = flipperStrength;
        spring.damper = flipperDamper;

        if (Input.GetButtonDown(inputButtonName))
        {
            spring.targetPosition = pressedPosition;
        }

        else if (Input.GetButtonUp(inputButtonName))
            spring.targetPosition = restPosition;

        joint.spring = spring;
        joint.useLimits = true;

        GetComponent<HingeJoint>().spring = spring;
        GetComponent<HingeJoint>().useLimits = true;
    }
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.JointSpring jointSpring = new UnityEngine.JointSpring();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "spring":
                    jointSpring.spring = reader.ReadProperty <System.Single> ();
                    break;

                case "damper":
                    jointSpring.damper = reader.ReadProperty <System.Single> ();
                    break;

                case "targetPosition":
                    jointSpring.targetPosition = reader.ReadProperty <System.Single> ();
                    break;
                }
            }
            return(jointSpring);
        }
Exemplo n.º 20
0
 private void INTERNAL_set_suspensionSpring(ref JointSpring value)
 {
     throw new NotImplementedException("なにこれ");
 }
Exemplo n.º 21
0
 private void INTERNAL_set_suspensionSpring(ref JointSpring value);
Exemplo n.º 22
0
 private extern void INTERNAL_set_spring(ref JointSpring value);
Exemplo n.º 23
0
 private extern void INTERNAL_set_suspensionSpring(ref JointSpring value);
Exemplo n.º 24
0
        private void MotorGoTo(float angle)
        {
            KAS_Shared.DebugLog("MotorGoTo(Rotor) - Go to angle : " + angle);
            if (!KAS_Shared.RequestPower(this.part, powerDrain)) return;

            fxSndMotorStart.audio.Play();
            if (!fxSndMotor.audio.isPlaying) fxSndMotor.audio.Play();
            rotorGoingTo = true;

            hingeJnt.useSpring = true;
            hingeJnt.useMotor = false;
            hingeJnt.useLimits = hasLimit;
            rotorActivated = true;

            JointSpring spr = new JointSpring();
            spr.spring = spring;
            spr.targetPosition = angle;
            spr.damper = damper;
            hingeJnt.spring = spr;
        }
Exemplo n.º 25
0
 public void updateSpring(float spring, float damper, float targetPosition)
 {
     JointSpring jointSpring = new JointSpring();
     jointSpring.spring = spring;
     jointSpring.damper = damper;
     jointSpring.targetPosition = targetPosition;
     for (int i = 0; i < wheels.Count; i++)
     {
         wheels[i].wheelCollider.suspensionSpring = jointSpring;
     }
 }
Exemplo n.º 26
0
 private extern void get_spring_Injected(out JointSpring ret);
Exemplo n.º 27
0
 private extern void set_suspensionSpring_Injected(ref JointSpring value);
Exemplo n.º 28
0
    void Start()
    {
        //Destroy existing rigidbody, we don't want anyone to mess with it.
        if(rigidbody)
            Destroy(rigidbody);

        //setup rigidbody
        gameObject.AddComponent<Rigidbody>();
        rigidbody.mass = mass;
        rigidbody.drag = drag;
        rigidbody.angularDrag = 0.05f;
        rigidbody.centerOfMass = new Vector3(rigidbody.centerOfMass.x, cogY, rigidbody.centerOfMass.z);
        rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
        //		rigidbody.constraints = RigidbodyConstraints.FreezeRotationZ;

        //start engine noise
        audio.loop = true;
        audio.Play();
        SMCamera = Camera.main.GetComponent<SmoothFollow>();
        //setup wheels
        wheels=new WheelData[4 + otherWheels.Length];
        for(int i=0;i<4 + otherWheels.Length;i++)
            wheels[i] = new WheelData();

        wheels[0].graphic = wheelFL;
        wheels[1].graphic = wheelFR;
        wheels[2].graphic = wheelBL;
        wheels[3].graphic = wheelBR;
        for(int i=0;i < otherWheels.Length;i++)
        {
            wheels[i + 4].graphic = otherWheels[i];
        }
        wheels[0].maxSteerAngle = 30.0f;
        wheels[1].maxSteerAngle = 30.0f;
        wheels[2].powered = true;
        wheels[3].powered = true;
        wheels[2].handbraked = true;
        wheels[3].handbraked = true;

        foreach(WheelData w in wheels)
        {
            if(w.graphic == null)
                Debug.Log("You need to assign all four wheels for the car script!");
            if(!w.graphic.transform.IsChildOf(transform))
                Debug.Log("Wheels need to be children of the Object with the car script");

            w.originalRotation = w.graphic.localRotation;

            //create collider
            GameObject colliderObject = new GameObject("WheelCollider");
            colliderObject.transform.parent = transform;
            colliderObject.transform.localPosition = w.graphic.localPosition;
            colliderObject.transform.localRotation = w.graphic.localRotation;
            w.coll = colliderObject.AddComponent<WheelCollider>();
            w.coll.suspensionDistance = suspensionDistance;
            JointSpring js = new JointSpring();
            js.spring = springs;
            js.damper = dampers;
        //			w.coll.suspensionSpring.spring = springs;
        //			w.coll.suspensionSpring.damper = dampers;
            w.coll.suspensionSpring = js;
            //no grip, as we simulate handling ourselves
            WheelFrictionCurve forwardwfc = new WheelFrictionCurve();
            forwardwfc.stiffness = 0;
            WheelFrictionCurve sidewaywfc = new WheelFrictionCurve();
            sidewaywfc.stiffness = 0;
        //			w.coll.forwardFriction.stiffness = 0;
        //			w.coll.sidewaysFriction.stiffness = 0;
            w.coll.forwardFriction = forwardwfc;
            w.coll.sidewaysFriction = sidewaywfc;
            w.coll.radius = wheelRadius;
        }

        //get wheel height (height forces are applied on)
        //		wheelY = wheels[0].graphic.localPosition.y;

        //find skidmark object
        skidmarks = FindObjectOfType(typeof(Skidmarks)) as Skidmarks;

        //shift to first
        gear = 1;
        defaultMaxRPM = maxRPM;
        defaultMaxTorque = maxTorque;
        carAI = GetComponent<CarAI>();
    }
Exemplo n.º 29
0
 private extern void set_spring_Injected(ref JointSpring value);
    //Not currently used
    void AddJointPhysics( int n )
    {
        Rigidbody rigid = joints[n].AddComponent<Rigidbody>();

        HingeJoint ph = joints[n].AddComponent<HingeJoint>();

        ph.axis = axis;
        ph.useSpring = true;
        ph.anchor = Vector3.zero;
        JointSpring tempSpring = new JointSpring();

        float range = joints.Length - 1;

        float seg = ( range - (float) n ) / range;

        if(n == tailIndex)
        {
            tempSpring.spring = tailSpring;
            tempSpring.damper = tailDamper;
            rigid.drag = tailJointDrag;
            rigid.mass = tailJointMass;
            ph.spring = tempSpring;
        }
        else
        {
            tempSpring.spring = spring  * (seg * ( 1 - taperMin ) + taperMin);
            tempSpring.damper = damper;
            rigid.drag = jointDrag * (seg * ( 1 - taperMin ) + taperMin);
            rigid.mass = jointMass * (seg * ( 1 - taperMin ) + taperMin);
        }

        tempSpring.targetPosition = 0.0f;
        ph.spring = tempSpring;

        if( n <= motorJointIndex && n != 0 )
        {
            joints[n-1].hingeJoint.connectedBody = rigid;
        }

        if( n == motorJointIndex)
        {
            rigid.isKinematic = true;

            GameObject helperJoint = new GameObject( joints[n].name + "_HelperJoint" );

            helperJoint.transform.parent = root.transform;
            helperJoint.transform.position = joints[n].transform.position;
            helperJoint.transform.rotation = joints[n].transform.rotation;

            Rigidbody hrb = helperJoint.AddComponent<Rigidbody>();
            HingeJoint hph = helperJoint.AddComponent<HingeJoint>();

            hrb.useGravity = false;
            hrb.mass = rigid.mass;
            hrb.drag = rigid.drag;
            hrb.angularDrag = 0.0f;
            hrb.isKinematic = false;

            hph.axis = ph.axis;
            hph.useSpring = ph.useSpring;
            hph.anchor = ph.anchor;
            hph.spring = ph.spring;

            hph.connectedBody = rigid;

            GameObject fixedJoint = new GameObject( joints[n].name + "_FixedJoint" );

            fixedJoint.transform.parent = root.transform;
            fixedJoint.transform.position = joints[n].transform.position;
            fixedJoint.transform.rotation = joints[n].transform.rotation;

            joints[n].transform.parent = fixedJoint.transform;

            Rigidbody rb = fixedJoint.AddComponent<Rigidbody>();
            FixedJoint fj = fixedJoint.AddComponent<FixedJoint>();

            rb.useGravity = false;
            rb.mass = 0.001f;
            rb.drag = 0.0f;
            rb.angularDrag = 0.0f;
            rb.isKinematic = false;

            if(n != 0)
            {
                fj.connectedBody = hrb;
            }

            if(useMotionTarget)
            {
                print(motionTarget.name);
                motionTarget.connectedBody = rb;
            }
        }

        else
        {
            rigid.isKinematic = false;
        }
        rigid.useGravity = false;

        if(n > motorJointIndex)
        {
            ph.connectedBody = joints[n-1].rigidbody;
        }
    }
Exemplo n.º 31
0
    private void InitializeJoints()
    {
        if (Joints != null)
        {
            DestroyJoints();
            return;
        }

        if (LinksCount == 0)
        {
            Debug.LogError("LinksCount can't be zero!");
            return;
        }

        Joints = new HingeJoint[LinksCount + 1];
        var Position = transform.TransformPoint(Anchor);
        var OtherPosition = ConnectedBody.transform.TransformPoint(RemoteAnchor);
        var DesiredPosition = Position + (OtherPosition - Position) * (1 - DesiredLengthRate);
        var PreviousPosition = transform.position;

        // Changing the position of the GameObject, so the created links will have the desired initial length.
        transform.position += DesiredPosition - Position;
        Position = transform.TransformPoint(Anchor);
        var Links = Enumerable.Range(0, LinksCount).Select(Index =>
        {
            var GameObject = new GameObject("Link");
            GameObject.transform.position = (Position*(LinksCount - Index) + OtherPosition*(1 + Index))/(LinksCount + 1);
            var RigidBody = GameObject.AddComponent<Rigidbody>();
            RigidBody.mass = RopeTotalMass / LinksCount;
            RigidBody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;
            GameObject.transform.parent = gameObject.transform;

            return GameObject;
        }).ToList();

        var PreviousLink = gameObject;
        var CurrentLink = gameObject;
        var SpringValues = new JointSpring {spring = SpringForce, damper = DampingRate, targetPosition = 0};
        for (int i = 0; i < LinksCount + 1; i++)
        {
            if (i != LinksCount)
                CurrentLink = Links[i];
            else
            {
                // Performing a switch, as the SpringJoint contains only anchor, and not remote-anchor.
                PreviousLink = ConnectedBody.gameObject;
            }

            var Joint = PreviousLink.AddComponent<HingeJoint>();
            Joint.spring = SpringValues;
            Joint.anchor = Vector3.zero;
            Joint.axis = new Vector3(0, 0, 1);
            Joint.connectedBody = CurrentLink.rigidbody;
            Joints[i] = Joint;

            PreviousLink = CurrentLink;
        }
        Joints[0].anchor = Anchor;
        Joints[LinksCount].anchor = RemoteAnchor;

        // Restoring the positions of the GameObject, and putting the links in their appropriate location.
        transform.position = PreviousPosition;
        Position = transform.TransformPoint(Anchor);
        for (var Index = 0; Index < Links.Count; Index++)
        {
            var Link = Links[Index];
            Link.transform.position = (Position * (LinksCount - Index) + OtherPosition * (1 + Index)) / (LinksCount + 1);
        }
    }
Exemplo n.º 32
0
    void FixedUpdate()
    {
        if ((Joints == null) || (Joints.Length != LinksCount + 1))
            InitializeJoints();

        if (Joints != null)
        {
            var SpringValues = new JointSpring {spring = SpringForce, damper = DampingRate, targetPosition = 0};
            foreach (var Joint in Joints)
            {
                Joint.useSpring = true;
                Joint.spring = SpringValues;
            }
        }
    }
Exemplo n.º 33
0
		private extern void INTERNAL_set_spring(ref JointSpring value);
Exemplo n.º 34
0
 private void INTERNAL_get_spring(out JointSpring value)
 {
     throw new NotImplementedException("なにこれ");
 }
Exemplo n.º 35
0
 // Conversion from JointLimit and JointSpring to SoftJointLimitSpring
 private static SoftJointLimitSpring ConvertToSoftJointLimitSpring(JointLimits src, JointSpring spring, bool useSpring)
 {
     SoftJointLimitSpring limitSpring = new SoftJointLimitSpring();
     limitSpring.damper = useSpring? spring.damper: 0f;
     limitSpring.spring = useSpring? spring.spring: 0f;
     return limitSpring;
 }
Exemplo n.º 36
0
        //when started
        public override void OnStart(PartModule.StartState start)
        {
            // degub only: print("onstart");
            base.OnStart(start);
            print(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);

            //this.part.AddModule("ModuleWaterSlider");
            if (HighLogic.LoadedSceneIsGame)
            {
            }
            if (HighLogic.LoadedSceneIsEditor)
            {
            }

            if (HighLogic.LoadedSceneIsFlight)
            {
                foreach (WheelCollider b in this.part.GetComponentsInChildren<WheelCollider>())
                {
                    repulsorCount += 1;
                    userspring = b.suspensionSpring;
                    userspring.spring = SpringRate;
                    userspring.damper = DamperRate;
                    b.suspensionSpring = userspring;
                    b.suspensionDistance = Rideheight;
                    wcList.Add(b);
                }

                this.part.force_activate(); //force the part active or OnFixedUpate is not called.
                currentRideHeight = Rideheight;
                UpdateHeight();

                foreach (ModuleWaterSlider mws in this.vessel.FindPartModulesImplementing<ModuleWaterSlider>())
                {
                    _MWS = mws;
                }

                //print("water slider height is" + _MWS.colliderHeight);

                _grid = transform.Search(gridName);

                //print(string.Format("Water slider height is{0}", _MWS.colliderHeight));

            }
            DestroyBounds();
            effectPowerMax = 1 * repulsorCount * chargeConsumptionRate * Time.deltaTime;
            //print("max effect power");
            //print(effectPowerMax);
        }
Exemplo n.º 37
0
 public void ResetSpringConfig()
 {
     JointSpring spr = new JointSpring();
     spr.spring = spring;
     spr.damper = damper;
     hingeJnt.spring = spr;
 }
Exemplo n.º 38
0
        //when started
        //begin start
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);

            susInc = KFPersistenceManager.suspensionIncrement;

            if (HighLogic.LoadedSceneIsFlight && !Equals(vessel.vesselType, VesselType.Debris)) // && vessel.parts.Count > 1) // Vessel could still be debris even with a part cound greater than one.
            {
                _grid = transform.Search(gridName);
                _gridScale = _grid.transform.localScale;
                _gimbal = transform.Search(gimbalName);

                foreach (WheelCollider b in part.GetComponentsInChildren<WheelCollider>())
                {
                    repulsorCount ++;
                    userspring = b.suspensionSpring;
                    userspring.spring = SpringRate;
                    userspring.damper = DamperRate;
                    b.suspensionSpring = userspring;
                    b.suspensionDistance = 2.5f; //default to low setting to save stupid shenanigans on takeoff
                    wcList.Add(b);
                }
                KFLog.Log(string.Format("Repulsor Count: {0}", repulsorCount));

                if (pointDown)
                {
                    StopAllCoroutines();
                    StartCoroutine("LookAt");
                }
                appliedRideHeight = rideHeight;
                StartCoroutine("UpdateHeight"); //start updating to height set before launch

                SetupDust(state);
                SetupWaterSlider();
                isReady = true;
            }
            DestroyBounds();
        }
Exemplo n.º 39
0
 private extern void get_suspensionSpring_Injected(out JointSpring ret);
Exemplo n.º 40
0
 static public int get_damper(IntPtr l)
 {
     UnityEngine.JointSpring o = (UnityEngine.JointSpring)checkSelf(l);
     pushValue(l, o.damper);
     return(1);
 }
Exemplo n.º 41
0
 private extern void INTERNAL_get_spring(out JointSpring value);
Exemplo n.º 42
0
 protected override void OnLoaded()
 {
     wheels = new WheelData[4];
     for (int i = 0; i < 4; i++)
         wheels[i] = new WheelData();
     wheels[0].graphic = wheelFL;
     wheels[1].graphic = wheelFR;
     wheels[2].graphic = wheelBL;
     wheels[3].graphic = wheelBR;
     wheels[0].maxSteerAngle = 30.0f;
     wheels[1].maxSteerAngle = 30.0f;
     wheels[2].powered = true;
     wheels[3].powered = true;
     wheels[2].handbraked = true;
     wheels[3].handbraked = true;
     foreach (WheelData w in wheels)
     {
         if (w.graphic == null)
             Debug.Log("You need to assign all four wheels for the car script!");
         if (!w.graphic.transform.IsChildOf(transform))
             Debug.Log("Wheels need to be children of the Object with the car script");
         w.originalRotation = w.graphic.localRotation;
         GameObject colliderObject = new GameObject("WheelCollider");
         colliderObject.transform.parent = transform;
         colliderObject.transform.position = w.graphic.position;
         w.coll = (WheelCollider)colliderObject.AddComponent(typeof(WheelCollider));
         w.coll.suspensionDistance = suspensionDistance;
         JointSpring t = new JointSpring();
         t.spring = springs;
         t.damper = dampers;
         w.coll.suspensionSpring = t;
         w.coll.forwardFriction = new WheelFrictionCurve();
         w.coll.sidewaysFriction = new WheelFrictionCurve();
         w.coll.radius = wheelRadius;
     }
     wheelY = wheels[0].graphic.localPosition.y;
     Skidmarks skidmarks = (Skidmarks)FindObjectOfType(typeof(Skidmarks));
     gear = 1;
 }
Exemplo n.º 43
0
 private extern void INTERNAL_get_suspensionSpring(out JointSpring value);
Exemplo n.º 44
0
 static public int get_targetPosition(IntPtr l)
 {
     UnityEngine.JointSpring o = (UnityEngine.JointSpring)checkSelf(l);
     pushValue(l, o.targetPosition);
     return(1);
 }
Exemplo n.º 45
0
    // --------------------------- Start ---------------------------------------------------------------------
    public void Start()
    {
        foreach (Transform child in transform)
        {
            if(child.gameObject.name.Contains("wheel")){
                if (wheels == null)
                    wheels = new List<WheelSet>();
                WheelSet wheel=new WheelSet();
                if(child.gameObject.name.Contains("f")){
                    wheel.steered = true;
                }
                wheel.wheelgraphic=child;
                wheel.powered = true;
                wheel.handbraked = true;
                wheel.wheelaxle = child;
                wheels.Add(wheel);
            }
        }
        // wheels enumerator
        if (wheels != null)
        {
            WheelsN = wheels.Count;

            foreach (WheelSet w in wheels)
            {
                w.originalRotation = w.wheelgraphic.rotation;
                w.originalBrakeRotation = w.wheelaxle.rotation;

                //create collider
                GameObject colliderObject = new GameObject("WheelC");
                colliderObject.transform.parent = transform;
                colliderObject.transform.position = w.wheelgraphic.position;
                w.wCollider = colliderObject.AddComponent<WheelCollider>();
                w.wCollider.suspensionDistance = springLength;
                JointSpring springSetup = new JointSpring();
                springSetup.spring = springForce;
                springSetup.damper = damperForce;
                w.wCollider.suspensionSpring = springSetup;
                WheelFrictionCurve forFrictionSetup = new WheelFrictionCurve();
                WheelFrictionCurve sideFrictionSetup = new WheelFrictionCurve();

                forFrictionSetup.stiffness = FrontSlip;
                sideFrictionSetup.stiffness = SideSlip;
                w.wCollider.forwardFriction = forFrictionSetup;
                w.wCollider.sidewaysFriction = sideFrictionSetup;
                w.wCollider.mass = WheelMass;
                w.wCollider.radius = WheelRadius;
                if (w.powered)
                {
                    MWheelsN++;
                }
                CurrentGear = 0;
            }
            // mass center adjustment
            rigidbody.centerOfMass = massCorrection;
            Debug.Log(rigidbody.centerOfMass);
        }
        else
        {
            Debug.LogError("No wheels assigned!");
        }
        if (MWheelsN == 0)
        {
            Debug.Log("No motor wheels assigned!");
        }
    }
Exemplo n.º 46
0
        public void setDefaultValues()
        {
            if (carAxiles.Count < 1)
            {
                CustomDebug.customLog("CarControllerInspector", "setDefaultValues()", "Car axiles are missing.");
                return;
            }

            carData.setDefaultValues();

            foreach (CarAxile carAxile in carAxiles)
            {
                JointSpring tempSpring = new JointSpring();
                WheelFrictionCurve tempWheelFrictCurveForward = new WheelFrictionCurve();
                WheelFrictionCurve tempWheelFrictCurveSide = new WheelFrictionCurve();

                //Left wheel
                carAxile.leftWheel.mass = carData.mass;
                carAxile.leftWheel.radius = carData.radius;
                carAxile.leftWheel.wheelDampingRate = carData.dampingRate;
                carAxile.leftWheel.suspensionDistance = carData.suspensionDistance;
                carAxile.leftWheel.forceAppPointDistance = carData.forceAppPointDistance;

                tempSpring.spring = carData.spring;
                tempSpring.damper = carData.damper;
                tempSpring.targetPosition = carData.targetPosition;
                carAxile.leftWheel.suspensionSpring = tempSpring;

                tempWheelFrictCurveForward.extremumSlip = carData.forwardExtremumSlip;
                tempWheelFrictCurveForward.extremumValue = carData.forwardExtremumValue;
                tempWheelFrictCurveForward.asymptoteSlip = carData.forwardAsymptoteSlip;
                tempWheelFrictCurveForward.asymptoteValue = carData.forwardAsymptoteValue;
                tempWheelFrictCurveForward.stiffness = carData.forwardStiffness;

                tempWheelFrictCurveSide.extremumSlip = carData.sideExtremumSlip;
                tempWheelFrictCurveSide.extremumValue = carData.sideExtremumValue;
                tempWheelFrictCurveSide.asymptoteSlip = carData.sideAsymptoteSlip;
                tempWheelFrictCurveSide.asymptoteValue = carData.sideAsymptoteValue;
                tempWheelFrictCurveSide.stiffness = carData.sideStiffness;

                carAxile.leftWheel.forwardFriction = tempWheelFrictCurveForward;
                carAxile.leftWheel.sidewaysFriction = tempWheelFrictCurveSide;

                //Right wheel
                carAxile.rightWheel.mass = carData.mass;
                carAxile.rightWheel.radius = carData.radius;
                carAxile.rightWheel.wheelDampingRate = carData.dampingRate;
                carAxile.rightWheel.suspensionDistance = carData.suspensionDistance;
                carAxile.rightWheel.forceAppPointDistance = carData.forceAppPointDistance;

                tempSpring.spring = carData.spring;
                tempSpring.damper = carData.damper;
                tempSpring.targetPosition = carData.targetPosition;
                carAxile.rightWheel.suspensionSpring = tempSpring;

                tempWheelFrictCurveForward.extremumSlip = carData.forwardExtremumSlip;
                tempWheelFrictCurveForward.extremumValue = carData.forwardExtremumValue;
                tempWheelFrictCurveForward.asymptoteSlip = carData.forwardAsymptoteSlip;
                tempWheelFrictCurveForward.asymptoteValue = carData.forwardAsymptoteValue;
                tempWheelFrictCurveForward.stiffness = carData.forwardStiffness;

                tempWheelFrictCurveSide.extremumSlip = carData.sideExtremumSlip;
                tempWheelFrictCurveSide.extremumValue = carData.sideExtremumValue;
                tempWheelFrictCurveSide.asymptoteSlip = carData.sideAsymptoteSlip;
                tempWheelFrictCurveSide.asymptoteValue = carData.sideAsymptoteValue;
                tempWheelFrictCurveSide.stiffness = carData.sideStiffness;

                carAxile.rightWheel.forwardFriction = tempWheelFrictCurveForward;
                carAxile.rightWheel.sidewaysFriction = tempWheelFrictCurveSide;
            }
            CustomDebug.customLog("CarControllerInspector", "setDefaultValues()", "CarData default values and wheel colliders are set.");
        }
Exemplo n.º 47
0
 private void INTERNAL_get_suspensionSpring(out JointSpring value);
	public override void OnSelection(RUISWandSelector selector)
	{
		updateHingePositionAndAxis();
		updateHingeForward();
		
		this.selector = selector;
		positionAtSelection = selector.selectionRayEnd;
		rotationAtSelection = transform.rotation;
		selectorPositionAtSelection = selector.transform.position;
		selectorRotationAtSelection = selector.transform.rotation;
		distanceFromSelectionRayOrigin = (selector.selectionRayEnd - selector.selectionRay.origin).magnitude; // Dont remove this, needed in the inherited class
		
		this.angleOnSelection = getHingeJointAngle();
		this.targetAngleOnSelection = getAngleDifferenceFromHingeForwardOnStart();
		
		this.originalJointSpring = transform.GetComponent<HingeJoint>().spring;
		
		if(!physicalSelection) 
		{
			JointSpring spr = GetComponent<HingeJoint>().spring;
			spr.spring = 0;
			spr.targetPosition = this.originalJointSpring.targetPosition;
			spr.damper = this.originalJointSpring.damper;
			GetComponent<HingeJoint>().spring = spr;
			this.useGravityOriginalValue = transform.GetComponent<Rigidbody>().useGravity;
			transform.GetComponent<Rigidbody>().useGravity = false;	
		}
		
		if (selectionMaterial != null)
			AddMaterialToEverything(selectionMaterial);
	}
Exemplo n.º 49
0
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);
            deployed = true;

            if ((Equals(resourceName, "none") || Equals(resourceConsumptionRate, 0f)) && usesResources) // Implied: usesResources has been set to true.
                usesResources = false;

            susInc = KFPersistenceManager.suspensionIncrement;

            if (HighLogic.LoadedSceneIsFlight && (!Equals(vessel.vesselType, VesselType.Debris) && !Equals(vessel.vesselType, VesselType.EVA)))
            {
                _grid = transform.Search(gridName);
                _gridScale = _grid.transform.localScale;
                _gimbal = transform.Search(gimbalName);

                foreach (WheelCollider foundCollider in part.GetComponentsInChildren<WheelCollider>())
                {
                    repulsorCount++;
                    userspring = foundCollider.suspensionSpring;
                    userspring.spring = SpringRate;
                    userspring.damper = DamperRate;
                    foundCollider.suspensionSpring = userspring;
                    foundCollider.suspensionDistance = 2.5f;
                    wcList.Add(foundCollider);
                }

                #if DEBUG
                KFLog.Log(string.Format("Repulsor Count: {0}", repulsorCount));
                #endif

                if (pointDown)
                {
                    StopAllCoroutines();
                    StartCoroutine("LookAt");
                }

                appliedRideHeight = rideHeight;
                StartCoroutine("UpdateHeight");

                SetupDust(state);
                SetupWaterSlider();
                isReady = true;
            }
            DestroyBounds();
        }
Exemplo n.º 50
0
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart (state);

            #region animationSetup
            animationController = SSTUAnimateControlled.locateAnimationController(part, animationID, onAnimationStatusChanged);
            #endregion

            #region gui setup
            Events["retractEvent"].guiName = retractGuiName;
            Events["deployEvent"].guiName = deployGuiName;
            Events["repairEvent"].guiName = repairGuiName;
            Actions["toggleAction"].guiName = actionGroupGuiName;

            Events["retractEvent"].active = legState==LegState.DEPLOYED;
            Events["deployEvent"].active = legState==LegState.RETRACTED;
            Events["repairEvent"].active = legState==LegState.BROKEN;
            #endregion

            #region colliderSetup
            if(HighLogic.LoadedSceneIsFlight)
            {
                //setup suspension upper limits, defaults to config value for suspension travel
                if(suspensionUpperLimit==-1){suspensionUpperLimit=suspensionTravel;}

                String[] wcNameArray = wheelColliderNames.Split(',');
                String[] susNameArray = suspensionTransformNames.Split(',');
                String[] footNameArray = footColliderNames.Split(',');
                int length = wcNameArray.Length < susNameArray.Length ? wcNameArray.Length : susNameArray.Length;

                LandingLegData legData;
                Transform suspensionTransform;
                Transform wheelColliderTransform;
                Transform footColliderTransform;
                WheelCollider wheelCollider;
                float wcRadius = 0, wcTravel = 0, wcTarget = 0, wcSpring = 0, wcDamper = 0;

                for(int i = 0; i < length; i++)
                {

                    suspensionTransform = part.FindModelTransform(susNameArray[i].Trim());
                    wheelColliderTransform = part.FindModelTransform(wcNameArray[i].Trim());
                    if(suspensionTransform==null || wheelColliderTransform==null)
                    {
                        print ("error locating transforms for names: "+susNameArray[i]+", "+wcNameArray[i]);
                        print ("found objects: "+suspensionTransform+", "+wheelColliderTransform);
                        continue;
                    }
                    wheelCollider = wheelColliderTransform.GetComponent<WheelCollider>();
                    if(wheelCollider==null)
                    {

                        print ("Wheel collider transform does not contain a valid wheel collider!  name: "+wcNameArray[i]);
                        SSTUUtils.recursePrintComponents(wheelColliderTransform.gameObject, "");
                        continue;
                    }
                    if(i<footNameArray.Length)
                    {
                        footColliderTransform = part.FindModelTransform(footNameArray[i].Trim ());
                    }
                    else
                    {
                        footColliderTransform = null;
                    }
                    legData = new LandingLegData();
                    legData.suspensionTransform = suspensionTransform;
                    legData.wheelCollider = wheelCollider;
                    legData.footColliderTransform = footColliderTransform;
                    this.legData.Add (legData);

                    //use default values if config values were not written
                    wcRadius = wheelColliderRadius==-1 ? wheelCollider.radius : wheelColliderRadius;
                    wcTravel = suspensionTravel==-1 ? wheelCollider.suspensionDistance : suspensionTravel;
                    wcTarget = suspensionTarget==-1 ? wheelCollider.suspensionSpring.targetPosition : suspensionTarget;
                    wcSpring = suspensionSpring==-1 ? wheelCollider.suspensionSpring.spring : suspensionSpring;
                    wcDamper = suspensionDamper==-1 ? wheelCollider.suspensionSpring.damper : suspensionDamper;

                    //setup wheel collider radius and suspension distance in case of overrides in config
                    wheelCollider.radius = wcRadius;
                    wheelCollider.suspensionDistance = wcTravel;
                    wheelCollider.brakeTorque = 1000f;

                    //setup a new JointSpring for the wheel to use, overriding values from config if needed
                    JointSpring spring = new JointSpring();
                    spring.spring = wcSpring;
                    spring.damper = wcDamper;
                    spring.targetPosition = wcTarget;
                    wheelCollider.suspensionSpring = spring;//assign the new spring joint to the wheel collider
                }
            }

            #endregion

            setLegState(legState);
            if(!moduleControlEnabled)
            {
                onControlDisabled();
            }
        }
Exemplo n.º 51
0
		private extern void INTERNAL_get_spring(out JointSpring value);
Exemplo n.º 52
0
 // Conversion from JointLimit and JointSpring to low SoftJointLimit
 private static SoftJointLimit ConvertToLowSoftJointLimit(JointLimits src, JointSpring spring, bool useSpring)
 {
     SoftJointLimit limit = new SoftJointLimit();
     limit.limit = -src.min;
     limit.bounciness = src.bounciness;
     return limit;
 }