Exemple #1
0
 // Use this for initialization
 void Start()
 {
     // Get the ConstantForce component, Game Logic Game Object, and Gamelogic component
     _force = GetComponent<ConstantForce> () as ConstantForce;
     GAMELOGIC = GameObject.FindGameObjectWithTag ("GAMELOGIC");
     _logic = GAMELOGIC.GetComponent<Gamelogic> () as Gamelogic;
 }
 static public int get_relativeForce(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.ConstantForce self = (UnityEngine.ConstantForce)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.relativeForce);
         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
 }
Exemple #3
0
 static public int constructor(IntPtr l)
 {
     UnityEngine.ConstantForce o;
     o = new UnityEngine.ConstantForce();
     pushObject(l, o);
     return(1);
 }
Exemple #4
0
 // Use this for initialization
 void Start()
 {
     Spinner_ob = transform.GetChild (0).gameObject;
     force = Spinner_ob.GetComponent<ConstantForce> () as ConstantForce;
     rig = Spinner_ob.GetComponent<Rigidbody> () as Rigidbody;
     ScoreObj = GameObject.FindGameObjectWithTag ("SCORESYSTEM");
     sys = ScoreObj.GetComponent<Scoresystem> () as Scoresystem;
 }
Exemple #5
0
 static public int set_relativeTorque(IntPtr l)
 {
     UnityEngine.ConstantForce o = (UnityEngine.ConstantForce)checkSelf(l);
     UnityEngine.Vector3       v;
     checkType(l, 2, out v);
     o.relativeTorque = v;
     return(0);
 }
 // Use this for initialization
 new void Start()
 {
     rbThruster = GameObject.FindGameObjectWithTag ("RightBackThruster");
     lbThruster = GameObject.FindGameObjectWithTag ("LeftBackThruster");
     rbtBody = rbThruster.GetComponent <Rigidbody>();
     lbtBody = lbThruster.GetComponent<Rigidbody> ();
     rbtForce = rbThruster.GetComponent<ConstantForce> ();
     lbtForce = lbThruster.GetComponent<ConstantForce> ();
     turnRight = 0;
     turnLeft = 0;
 }
 static public int get_torque(IntPtr l)
 {
     try {
         UnityEngine.ConstantForce self = (UnityEngine.ConstantForce)checkSelf(l);
         pushValue(l, self.torque);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 /// <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.ConstantForce constantForce = (UnityEngine.ConstantForce)value;
     writer.WriteProperty("force", constantForce.force);
     writer.WriteProperty("relativeForce", constantForce.relativeForce);
     writer.WriteProperty("torque", constantForce.torque);
     writer.WriteProperty("relativeTorque", constantForce.relativeTorque);
     writer.WriteProperty("enabled", constantForce.enabled);
     writer.WriteProperty("tag", constantForce.tag);
     writer.WriteProperty("name", constantForce.name);
     writer.WriteProperty("hideFlags", constantForce.hideFlags);
 }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.ConstantForce o;
			o=new UnityEngine.ConstantForce();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Exemple #10
0
    // Use this for initialization
    void Start()
    {
        // If this flipper is on the left, change the input mapping accordingly
        if (bIsLeft) {
            _iFlipButton = 0;
            _sFlipper = "FlipLeft";
        }

        // Get the Rigidbody and ConstantForce components attached to flipper Game Object
        _rig = gameObject.GetComponent<Rigidbody> () as Rigidbody;
        _force = gameObject.GetComponent<ConstantForce> () as ConstantForce;
    }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.ConstantForce o;
         o = new UnityEngine.ConstantForce();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #12
0
 static public int get_torque(IntPtr l)
 {
     try {
         UnityEngine.ConstantForce self = (UnityEngine.ConstantForce)checkSelf(l);
         pushValue(l, self.torque);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int constructor(IntPtr l)
 {
     LuaDLL.lua_remove(l, 1);
     UnityEngine.ConstantForce o;
     if (matchType(l, 1))
     {
         o = new UnityEngine.ConstantForce();
         pushObject(l, o);
         return(1);
     }
     LuaDLL.luaL_error(l, "New object failed.");
     return(0);
 }
Exemple #14
0
	// Use this for initialization
	void Start () {
		/*cf = gameObject.GetComponent<ConstantForce>();
		radius = 50;

		pos1 = new Vector3(120.06f, 25.5f, 36.2f);
		pos2 = new Vector3(120.06f, 22.5f, 120f);

		collsPos1 = Physics.OverlapSphere (pos1, radius);
		collsPos2 = Physics.OverlapSphere (pos2, radius);*/
		cf = gameObject.GetComponent<ConstantForce>();
		rb = gameObject.GetComponent<Rigidbody>();
		newZ = cf.force.z;
	}
Exemple #15
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.ConstantForce o;
         o = new UnityEngine.ConstantForce();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static public int set_torque(IntPtr l)
 {
     try {
         UnityEngine.ConstantForce self = (UnityEngine.ConstantForce)checkSelf(l);
         UnityEngine.Vector3       v;
         checkType(l, 2, out v);
         self.torque = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.ConstantForce o;
         o=new UnityEngine.ConstantForce();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Exemple #18
0
 // Use this for initialization
 void Start()
 {
     Launcher.transform.position = Start_Pos.transform.position;
     fDistanceDiff = Start_Pos.transform.localPosition.z - End_Pos.transform.localPosition.z;
     if (fDistanceDiff < 0) {
         fDistanceDiff *= -1.0f;
     }
     LauncherForce = Launcher.GetComponent<ConstantForce> () as ConstantForce;
     rig = Launcher.GetComponent<Rigidbody> () as Rigidbody;
     rep = Launcher.transform.GetChild (0).GetComponent<Repel> () as Repel;
     rep.ChangeRepel (0.0f);
     Launcher_Child = Launcher.transform.GetChild (0).gameObject;
 }
 static public int set_relativeForce(IntPtr l)
 {
     try {
         UnityEngine.ConstantForce self = (UnityEngine.ConstantForce)checkSelf(l);
         UnityEngine.Vector3       v;
         checkType(l, 2, out v);
         self.relativeForce = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #20
0
 static public int set_relativeForce(IntPtr l)
 {
     try {
         UnityEngine.ConstantForce self = (UnityEngine.ConstantForce)checkSelf(l);
         UnityEngine.Vector3       v;
         checkType(l, 2, out v);
         self.relativeForce = v;
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 static void ConstantForce_relativeTorque(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.ConstantForce _this = (UnityEngine.ConstantForce)vc.csObj;
         var result = _this.relativeTorque;
         JSApi.setVector3S((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Vector3       arg0  = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
         UnityEngine.ConstantForce _this = (UnityEngine.ConstantForce)vc.csObj;
         _this.relativeTorque = arg0;
     }
 }
    void fly()
    {
        cf = GetComponent<ConstantForce> ();
        OVRPlayerController sc = GetComponent<OVRPlayerController> ();
        sc.Jump ();

        //float theta = Mathf.Asin((lastPos.y - llastPos.y) / Mathf.Sqrt(Mathf.Pow(lastPos.z - llastPos.z, 2) + Mathf.Pow (lastPos.y - llastPos.y, 2)));
        /*Vector3 newv = cf.force;
        newv.y -= 500;
        //newv.z = 0;

        //newv.z = Mathf.Cos (theta * cf.force.z);
        //newv.y = cf.force.z + 10f;//Mathf.Sin (Mathf.PI / 4 * cf.force.z);

        cf.force = newv;*/
    }
Exemple #23
0
    static int get_constantForce(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.GameObject    obj = (UnityEngine.GameObject)o;
            UnityEngine.ConstantForce ret = obj.constantForce;
            ToLua.PushSealed(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index constantForce on a nil value"));
        }
    }
    static int get_constantForce(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Component     obj = (UnityEngine.Component)o;
            UnityEngine.ConstantForce ret = obj.constantForce;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index constantForce on a nil value" : e.Message));
        }
    }
	// Use this for initialization
	void Start () 
	{
		InitCameraRotation = GameObject.Find("Main Camera").transform.rotation; 
		
		mPrefabArray = new ArrayList();
		for (int i = 0; i < TERRAIN_PREFABS.Length; i++)
		{
			mPrefabArray.Add(TERRAIN_PREFABS[i]);
		}
		
		TERRAIN_PREFABS = ShufflePrefabs(mPrefabArray);
		
		mPlayerForce = player.constantForce; 
		mAudioSrc = gameObject.GetComponent<AudioSource>(); 
		
		SwitchState(mGameState); 
	}
Exemple #26
0
    void Start()
    {
        m_GameObject = this.gameObject;
        m_Body = this.rigidbody;

        if (!m_Body)
        {
            Debug.Log("Warning : LocalGravity is attach to a gameobject without rigidbody !");
            return;
        }

        m_Body.useGravity = false;

        m_ConstForce = m_GameObject.AddComponent<ConstantForce>();
        setGravityDir(m_StartDir);
        m_Player = GetComponent<ControlerScript>();
    }
    // Use this for initialization
    void Start()
    {
        body = GetComponent<Rigidbody>();
        force = GetComponent<ConstantForce>();

        // Movement Variables
        maxPropulsionForce = 100.0f;
        maxPropulsionAccel = maxPropulsionForce;
        maxPropulsionVelocity = 300.0f;
        propulsionDrag = maxPropulsionAccel / maxPropulsionVelocity;

        maxTorqueForce = 25f;
        maxTorqueAccel = maxTorqueForce;
        maxTorqueVelocity = 50f;
        torqueDrag = maxTorqueAccel / maxTorqueVelocity;

        body.drag = propulsionDrag / (propulsionDrag * Time.fixedDeltaTime + 1);
        body.angularDrag = 6 * torqueDrag / (torqueDrag * Time.fixedDeltaTime + 1);
    }
        /// <summary>
        /// Read the data into the specified value.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="reader">Reader.</param>
        public override void ReadInto(object value, ISaveGameReader reader)
        {
            UnityEngine.ConstantForce constantForce = (UnityEngine.ConstantForce)value;
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "force":
                    constantForce.force = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "relativeForce":
                    constantForce.relativeForce = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "torque":
                    constantForce.torque = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "relativeTorque":
                    constantForce.relativeTorque = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "enabled":
                    constantForce.enabled = reader.ReadProperty <System.Boolean> ();
                    break;

                case "tag":
                    constantForce.tag = reader.ReadProperty <System.String> ();
                    break;

                case "name":
                    constantForce.name = reader.ReadProperty <System.String> ();
                    break;

                case "hideFlags":
                    constantForce.hideFlags = reader.ReadProperty <UnityEngine.HideFlags> ();
                    break;
                }
            }
        }
Exemple #29
0
 // Use this for initialization
 void Start()
 {
     _force = GetComponent<ConstantForce> ();
     reset ();
 }
Exemple #30
0
 void Start()
 {
     body = GetComponent<Rigidbody>();
     if (isLocalPlayer) {
         speedometer = (Text) FindObjectOfType (typeof(Text));
         GameObject camera = GameObject.FindGameObjectWithTag ("MainCamera");
         camera.GetComponent<TrackingCamera> ().Target = camTarget.transform;
     } else {
         force = GetComponent<ConstantForce> ();
     }
 }
 public MovementKeys(ConstantForce force, float speed)
 {
     this.force = force;
     this.speed = speed;
 }
Exemple #32
0
 static public int get_relativeTorque(IntPtr l)
 {
     UnityEngine.ConstantForce o = (UnityEngine.ConstantForce)checkSelf(l);
     pushValue(l, o.relativeTorque);
     return(1);
 }
 // Use this for initialization
 void Start()
 {
     sys = this.GetComponent<ParticleSystem>();
     force = this.GetComponent<ConstantForce>();
 }
    void Start()
    {
        m_Body = this.rigidbody;

        if (!m_Body)
        {
            return;
        }

        m_Body.useGravity = false;

        m_ConstForce = gameObject.AddComponent<ConstantForce>();
        SetGravityDir(m_StartDir);
        m_Player = GetComponent<ControllerScript>();
    }
 /// <summary>
 /// Caches all of the current standard components attached to the object.
 /// </summary>
 public void ResetCache()
 {
     animation = GetComponent<Animation>();
     audio = GetComponent<AudioSource>();
     camera = GetComponent<Camera>();
     collider = GetComponent<Collider>();
     collider2D = GetComponent<Collider2D>();
     constantForce = GetComponent<ConstantForce>();
     guiText = GetComponent<GUIText>();
     guiTexture = GetComponent<GUITexture>();
     hingeJoint = GetComponent<HingeJoint>();
     light = GetComponent<Light>();
     networkView = GetComponent<NetworkView>();
     particleEmitter = GetComponent<ParticleEmitter>();
     particleSystem = GetComponent<ParticleSystem>();
     renderer = GetComponent<Renderer>();
     rigidbody = GetComponent<Rigidbody>();
     rigidbody2D = GetComponent<Rigidbody2D>();
     transform = GetComponent<Transform>();
 }
        private void InitDoor()
        {
            Utilities.CreateColliders(getDoor());

            doorRb = getDoor().GetComponent<Rigidbody>();
            if (doorRb == null)
            {
                doorRb = getDoor().AddComponent<Rigidbody>();
                doorRb.angularDrag = DOOR_ANGULAR_DRAG;
            }
            doorRb.collisionDetectionMode = CollisionDetectionMode.Continuous; // otherwise door will not react to fast moving controller
            doorRb.isKinematic = false; // in case nested door as already created this

            doorHj = getDoor().GetComponent<HingeJoint>();
            if (doorHj == null)
            {
                doorHj = getDoor().AddComponent<HingeJoint>();
                doorHjCreated = true;
            }
            doorHj.connectedBody = frameRb;

            doorCf = getDoor().GetComponent<ConstantForce>();
            if (doorCf == null)
            {
                doorCf = getDoor().AddComponent<ConstantForce>();
                doorCf.enabled = false;
                doorCfCreated = true;
            }
        }
    // Update is called once per frame
    void Update()
    {
        ThalmicMyo thalmicMyo = myo.GetComponent<ThalmicMyo> ();
        rb = GetComponent<Rigidbody> ();
        cf = GetComponent<ConstantForce> ();
        Vector3 newv = cf.force;
        float newaf = rb.angularDrag;

        if (lastPos.y < transform.position.y) {
            goingUp = true;
        }

        if (goingUp) {
            newaf += 0.3f;
            rb.angularDrag = newaf;
        } else {
            if (rb.angularDrag > 1) {
                newaf -= 0.5f;
                rb.angularDrag = newaf;
            }
        }

        if (goingUp && (lastPos.y > transform.position.y)) {
            //fly();
            goingUp = false;
        } else {
            llastPos = lastPos;
            lastPos = transform.position;
        }
        //if (Input.GetKey (KeyCode.Space)) {
        if ((thalmicMyo.accelerometer.x < -0.4) || Input.GetKey (KeyCode.Space)) {
            //clip.Play ();
            //Debug.Log("drag decrease");
            if (rb.drag > 0.3f) {
                rb.drag -= 0.5f;
            }
            if (cf.force.z > -25) {
                newv.z -= 1f;
                //newv.y -= 1f;
                cf.force = newv;
            }
            spacedown = true;
            //ExtendUnlockAndNotifyUserAction (thalmicMyo);*/
            //this is wings expanded
            //should slow down and jump
            clip.Stop ();
        } else {
            //Debug.Log("resting");
            if (spacedown == true) {
                fly ();
                spacedown = false;
            }
            spacedown = false;
            if (rb.drag < 10f) {
                rb.drag += 0.5f;
            }
            if (cf.force.z < -15f) {
                newv.z += 0.5f;
                //newv.y += 1f;
                cf.force = newv;
            }
        }
            //ExtendUnlockAndNotifyUserAction (thalmicMyo);

        /*if (Input.GetKey (KeyCode.Space)) {

            if (rb.drag > 0.6f) {
                rb.drag -= 0.4f;
            }
            if (cf.force.z > -70) {
                newv.z -= 2f;
                //newv.y -= 1f;
                cf.force = newv;
            }
            spacedown = true;
        } else {
            if (spacedown == true) {
                    fly();
                    spacedown = false;
            }
            spacedown = false;
            if (rb.drag < 10f) {
                rb.drag += 0.3f;
            }
            if (cf.force.z < -15f) {
                newv.z += 0.1f;
                //newv.y += 1f;
                cf.force = newv;
            }
        }*/
    }
 private void Start()
 {
     m_RigidBody = GetComponent<Rigidbody>();
     m_Capsule = GetComponent<CapsuleCollider>();
     mouseLook.Init(transform, cam.transform);
     myConstantForce = GetComponent<ConstantForce>();
 }
 void Start()
 {
     controlPoint.addProcessFuncFloatArg(setForceRate);
     myConstantForce = constantForce;
     setForceRate(0f);
 }
        protected virtual void Awake()
        {
            _thisMovingObject = GetComponent<IMovingObject>();
            _movementStats = _thisMovingObject.MovementStats;

            _rigidBody = GetComponent<Rigidbody>();
            _constantForce = GetComponent<ConstantForce>();

            _movementVector = transform.forward;

            _currentBoostCharges = _movementStats.MaxBoostCharges;
            //_boostParticlesR = transform.Find("BoostParticles_R").GetComponent<ParticleSystem>();
            //_boostParticlesR.gameObject.SetActive(false);
            //_boostParticlesL = transform.Find("BoostParticles_L").GetComponent<ParticleSystem>();
            //_boostParticlesL.gameObject.SetActive(false);
            _cruiserSpeedParticles = transform.FindChild("CruiserSpeedParticles").GetComponent<ParticleSystem>();
            _cruiserSpeedParticles.gameObject.SetActive(false);

            _cruiserSpeedCharger = new Cooldown(_movementStats.SecondsForCruiserSpeed, _thisMovingObject, true);
            _cruiserSpeedCharger.OnReady += (Cooldown cd) => EnableCruiserSpeed();
            _cruiserSpeedCharger.OnStop += (Cooldown cd) => DisableCruiserSpeed();

            _boostChargesWasteFixer = new Cooldown(BoostChargesWasteInterval, _thisMovingObject);
        }
        protected override void InitRequiredComponents()
        {
            restingPosition = transform.position;

            if (!GetComponent<Collider>())
            {
                gameObject.AddComponent<BoxCollider>();
            }

            rb = GetComponent<Rigidbody>();
            if (rb == null)
            {
                rb = gameObject.AddComponent<Rigidbody>();
            }
            rb.isKinematic = false;
            rb.useGravity = false;

            cf = GetComponent<ConstantForce>();
            if (cf == null)
            {
                cf = gameObject.AddComponent<ConstantForce>();
            }

            if (connectedTo)
            {
                Rigidbody rb2 = connectedTo.GetComponent<Rigidbody>();
                if (rb2 == null)
                {
                    rb2 = connectedTo.AddComponent<Rigidbody>();
                }
                rb2.useGravity = false;
            }
        }
 // Use this for initialization
 void Start()
 {
     ms=GetComponentsInChildren<MechinePart>();
     wheelForse=gameObject.GetComponentInChildren<ConstantForce>();
 }
 /// <summary>
 /// Calls GetComponent for all cached components if the currently cached instance is no longer valid.
 /// </summary>
 public void ResetCacheDestroyed()
 {
     if (!animation)
     {
         animation = GetComponent<Animation>();
     }
     if (!audio)
     {
         audio = GetComponent<AudioSource>();
     }
     if (!camera)
     {
         camera = GetComponent<Camera>();
     }
     if (!collider)
     {
         collider = GetComponent<Collider>();
     }
     if (!collider2D)
     {
         collider2D = GetComponent<Collider2D>();
     }
     if (!constantForce)
     {
         constantForce = GetComponent<ConstantForce>();
     }
     if (!guiText)
     {
         guiText = GetComponent<GUIText>();
     }
     if (!guiTexture)
     {
         guiTexture = GetComponent<GUITexture>();
     }
     if (!hingeJoint)
     {
         hingeJoint = GetComponent<HingeJoint>();
     }
     if (!light)
     {
         light = GetComponent<Light>();
     }
     if (!networkView)
     {
         networkView = GetComponent<NetworkView>();
     }
     if (!particleEmitter)
     {
         particleEmitter = GetComponent<ParticleEmitter>();
     }
     if (!particleSystem)
     {
         particleSystem = GetComponent<ParticleSystem>();
     }
     if (!renderer)
     {
         renderer = GetComponent<Renderer>();
     }
     if (!rigidbody)
     {
         rigidbody = GetComponent<Rigidbody>();
     }
     if (!rigidbody2D)
     {
         rigidbody2D = GetComponent<Rigidbody2D>();
     }
     if (!transform)
     {
         transform = GetComponent<Transform>();
     }
 }
 /// <summary>
 /// Caches the current ConstantForce attached to the object.
 /// </summary>
 public void ResetConstantForceCache()
 {
     constantForce = GetComponent<ConstantForce>();
 }
    // INITIALIZOR
    void Start()
    {
        cc = GetComponent<Rigidbody>();
        anm = GetComponent<Animator>();
        col = GetComponent<CapsuleCollider>();
        cf = GetComponent<ConstantForce>();
        p = GetComponent<Player>();
        ik = GetComponent<BipedIK>();
        // put sword sheathed
        WeaponChanged();

        UpdateSpellUI();
        //Cursor.visible = false;
    }
        protected override void InitRequiredComponents()
        {
            initialPosition = transform.position;
            initialLocalPosition = transform.localPosition;

            rb = GetComponent<Rigidbody>();
            if (rb == null)
            {
                rb = gameObject.AddComponent<Rigidbody>();
            }
            rb.isKinematic = false;
            rb.useGravity = false;

            cf = GetComponent<ConstantForce>();
            if (cf == null)
            {
                cf = gameObject.AddComponent<ConstantForce>();
            }
            cf.enabled = false;
        }
 /// <summary>
 /// Read the data using the reader.
 /// </summary>
 /// <param name="reader">Reader.</param>
 public override object Read(ISaveGameReader reader)
 {
     UnityEngine.ConstantForce constantForce = SaveGameType.CreateComponent <UnityEngine.ConstantForce> ();
     ReadInto(constantForce, reader);
     return(constantForce);
 }
    protected virtual void Awake()
    {
        m_hForward = false;
        m_hBackward = false;
        m_hRight = false;
        m_hLeft = false;

        m_hWheels = new List<Wheel>();
        m_hRigidbody = this.GetComponent<Rigidbody>();
        m_hRigidbody.interpolation = RigidbodyInterpolation.None;
        //Initialize effective wheels
        List<Transform> gfxPos = this.GetComponentsInChildren<Transform>().Where(hT => hT.GetComponent<WheelCollider>() == null).ToList();
        this.GetComponentsInChildren<WheelCollider>().ToList().ForEach(hW => m_hWheels.Add(new Wheel(hW, gfxPos.OrderBy(hP => Vector3.Distance(hP.position, hW.transform.position)).First().gameObject)));
        m_hWheels = m_hWheels.OrderByDescending(hW => hW.Collider.transform.localPosition.z).ToList();

        //Initialize extra wheels
        m_hFakeWheels = GetComponentsInChildren<FakeWheel>().ToList();

        //Initialize VehicleTurret
        m_hTurret = GetComponentInChildren<VehicleTurret>();

        //Initialize IWeapon
        m_hCurrentWeapon = GetComponentInChildren<IWeapon>();

        m_hActor = GetComponent<Actor>();

        //Initialize Drive/Brake System
        switch (DriveType)
        {
            case DriveType.AWD:
                m_hEngine = new AwdDrive(Hp, m_hWheels);
                break;
            case DriveType.RWD:
                m_hEngine = new RearDrive(Hp, m_hWheels);
                break;
            case DriveType.FWD:
                m_hEngine = new ForwardDrive(Hp, m_hWheels);
                break;
            default:
                break;
        }


        m_hConstanForce = this.GetComponent<ConstantForce>();
        m_hReverseCOM = new Vector3(0.0f, -2.0f, 0.0f);

        m_hOriginalCOM = m_hRigidbody.centerOfMass;


        GroundState hGroundState = new GroundState(this);
        FlyState hFlyState = new FlyState(this);
        TurnedState hTurned = new TurnedState(this, m_hReverseCOM);

        hGroundState.Next = hFlyState;
        hFlyState.Grounded = hGroundState;
        hFlyState.Turned = hTurned;
        hTurned.Next = hFlyState;
        m_hFlyState = hFlyState;
    }