AddTorque() private method

private AddTorque ( float torque, [ mode ) : void
torque float
mode [
return void
コード例 #1
0
 static public int AddTorque(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.Rigidbody2D self = (UnityEngine.Rigidbody2D)checkSelf(l);
             System.Single           a1;
             checkType(l, 2, out a1);
             self.AddTorque(a1);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.Rigidbody2D self = (UnityEngine.Rigidbody2D)checkSelf(l);
             System.Single           a1;
             checkType(l, 2, out a1);
             UnityEngine.ForceMode2D a2;
             checkEnum(l, 3, out a2);
             self.AddTorque(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function AddTorque to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #2
0
 static public int AddTorque(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(float), typeof(UnityEngine.ForceMode2D)))
         {
             UnityEngine.Rigidbody2D self = (UnityEngine.Rigidbody2D)checkSelf(l);
             System.Single           a1;
             checkType(l, 2, out a1);
             UnityEngine.ForceMode2D a2;
             checkEnum(l, 3, out a2);
             self.AddTorque(a1, a2);
             return(0);
         }
         else if (matchType(l, 2, typeof(float)))
         {
             UnityEngine.Rigidbody2D self = (UnityEngine.Rigidbody2D)checkSelf(l);
             System.Single           a1;
             checkType(l, 2, out a1);
             self.AddTorque(a1);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #3
0
	void Start() {
		aiai = GetComponent<Rigidbody2D> ();

		Vector2 dytt = new Vector2 (Random.Range (-100.0f, 100.0f),
			               			Random.Range (-100.0f, 100.0f));
		
		aiai.AddTorque(Random.Range(-100.0f, 100.0f));
		aiai.AddForce (dytt, ForceMode2D.Impulse);
	}
コード例 #4
0
ファイル: EnemyClass.cs プロジェクト: davybolivar/Blockade
 public virtual void Die(Rigidbody2D rb)
 {
     rb.fixedAngle = false;
     //		rb.AddForce (new Vector2(Random.Range(3,4),Random.Range(40,80)));
     //		rb.AddForce (new Vector2(4,50f));
     rb.gravityScale = 7;
     rb.AddTorque(30f);
     gameObject.GetComponent<CircleCollider2D> ().isTrigger = true;
     //		Invoke ("DestroyObject",5f);
 }
コード例 #5
0
ファイル: ItemBall.cs プロジェクト: MickPlaYer/PinBallRPG
 // Use this for initialization
 void Start()
 {
     // Set random motion at start.
     float torque = Random.Range(100, 1000);
     float sign = Mathf.Sign(Random.value - 0.5f);
     Vector2 vector = Random.insideUnitCircle;
     _rigidbody = GetComponent<Rigidbody2D>();
     _rigidbody.AddTorque(torque * sign, ForceMode2D.Force);
     _rigidbody.AddForce(vector * 100, ForceMode2D.Force);
 }
コード例 #6
0
ファイル: Asteroid.cs プロジェクト: Jamroah/AsteroidsClone
    public override void OnEnable()
    {
        base.OnEnable();
        m_rigidbody2D = GetComponent<Rigidbody2D>();
        m_rigidbody2D.AddTorque(Random.Range(-100, 100));
        CurrentHealth = MaxHealth;

        if(sprites.Length > 0)
            GetComponent<SpriteRenderer>().sprite = sprites[Random.Range(0, sprites.Length)];
    }
コード例 #7
0
ファイル: AddTorque.cs プロジェクト: wuxijin999/Plugin
        public override TaskStatus OnUpdate()
        {
            if (targetRigidbody2D == null)
            {
                Debug.LogWarning("Rigidbody2D is null");
                return(TaskStatus.Failure);
            }

            targetRigidbody2D.AddTorque(torque.Value);

            return(TaskStatus.Success);
        }
コード例 #8
0
    // Use this for initialization
    void Start()
    {
        attitudeControllers = new List<GameObject>();
        physicsBody = GetComponent<Rigidbody2D>();

        physicsBody.AddTorque(10000);

        foreach (Transform child in transform) {
            if (child.gameObject.name == "Attitude") {
                attitudeControllers.Add(child.gameObject);
            }
        }
    }
コード例 #9
0
    // Use this for initialization
    void Start()
    {
        r2d = GetComponent<Rigidbody2D>();

        r2d.AddForce(-Vector2.right.Rotate(Random.Range(-minYAngle, -maxYAngle)) * Random.Range(minImpulse, maxImpulse), ForceMode2D.Impulse);
        r2d.AddTorque(Random.Range(minTorque, maxTorque));

        startY = transform.position.y;
        gravity = true;

        if (sprites != null && sprites.Length > 0)
        {
            GetComponent<SpriteRenderer>().sprite = Random2.RandomArrayElement(sprites);
        }
    }
コード例 #10
0
    void Start()
    {
        m_randomOffset = Random.Range(0.0f, 1.0f);
        float parenty = transform.parent.localPosition.y;

        m_targetY = Random.Range(transform.localPosition.y - 2.0f, transform.localPosition.y);

        if(m_targetY + parenty > -2.0f)
        {
            m_targetY = Random.Range(-10.0f - parenty, -4.0f - parenty);
        }

        m_rigidbody = GetComponent<Rigidbody2D>();
        m_rigidbody.AddForce(new Vector2(Random.Range(-10.0f, 10.0f), Random.Range(1.0f, 10.0f)), ForceMode2D.Impulse);
        m_rigidbody.AddTorque(Random.Range(10.0f, 100.0f));
    }
コード例 #11
0
 void Awake()
 {
     hpScript = GetComponent<HealthScript> ();
     sprite = GetComponent<SpriteRenderer> ();
     player = GameObject.FindGameObjectWithTag ("Player");
     WorldGen = GameObject.Find ("WorldGenerator").GetComponent<WorldGenerator>();
     float size = Random.Range (minSize, maxSize);
     float torque = Random.Range (minTorque, maxTorque);
     float force = Random.Range (minForce, maxForce);
     transform.Rotate(0.0f, 0.0f, Random.Range(0.0f, 360.0f));
     transform.localScale = new Vector3 (size, size, size);
     rb = GetComponent<Rigidbody2D> ();
     rb.mass = size * 2000;
     rb.AddTorque (torque, ForceMode2D.Impulse);
     rb.AddForce (transform.up * force, ForceMode2D.Impulse);
     hpScript.maxHp = Mathf.RoundToInt(30 * size);
     hpScript.hp = Mathf.RoundToInt(hpScript.maxHp - Random.Range (0, hpScript.maxHp));
 }
コード例 #12
0
	void OnTriggerEnter2D(Collider2D other) {
		//DEAD DEBUG BELOW
		if (other.gameObject.tag == "Goal") {
			goalHit=true;
			GameObject.FindWithTag("Timer").GetComponent<Timer>().Stop();
			if(useHelmet){
				GameObject.FindWithTag("Helmet").SetActive(false);
			}
			GetComponent<PinguNoises>().shouldMakeSound = false;
			GetComponent<OlafSigh>().dead = true;
			GameObject.FindWithTag("JetPackSounds").GetComponent<JetpackSound>().levelDone = true;
		}
		if (other.gameObject.tag == "Laser" && debug == false) {
			//play explosions and 2 sec later restart? feels nice with insta restart. mby sound
			Dead();
			
		}

		//Activate Physics objects
		if (other.gameObject.tag == "PhysicsObject" && other.GetComponent<Rigidbody2D>().isKinematic == true) {
			pObjectToActivate = other.GetComponent<Rigidbody2D>();
			pObjectToActivate.isKinematic = false;
			torqueToAdd = UnityEngine.Random.Range(-7f, 7f);
			pObjectToActivate.AddTorque(torqueToAdd, ForceMode2D.Force);
		}
		
		if (other.gameObject.tag == "Fuel") {		
			Fuel += 100;
			Destroy (other.gameObject);
			print ("FEUL DAMNIT");

			if (Fuel > maxFuel)
				Fuel = maxFuel;
		} 
		if (other.gameObject.tag == "ZoneHide") {
			detectable = false;
			print("HIDE");
		}/*
		else if (other.gameObject.tag == "Bouncer") {
			//bounces pingu
			Vector2 pos= new Vector2(0,0);
			pos.x = Mathf.Abs(rigidbody2D.position.x) - Mathf.Abs(other.transform.position.x);
			pos.y = Mathf.Abs(rigidbody2D.position.y) - Mathf.Abs(other.transform.position.y);
			
			if(Mathf.Abs(pos.x)<Mathf.Abs(pos.y)){
				print ("ByttY");
				print (rigidbody2D.velocity.y);
				Vector2 v =rigidbody2D.velocity;
				v.y = Mathf.Round(rigidbody2D.velocity.y);
				v.y = -v.y;
				if(v.y>0 && v.y<7.0f)
					v.y=8.3f;
				else if(v.y<0 && v.y>-7.0f)
					v.y=-8.3f;
				rigidbody2D.velocity = v;
				
				print (rigidbody2D.velocity.y);
			}

			else if(Mathf.Abs(pos.x)>Mathf.Abs(pos.y)){
				Vector2 v = rigidbody2D.velocity;
				v.x = Mathf.Round(rigidbody2D.velocity.x);
				v.x = -v.x;
				if(v.x>0 && v.x<7.0f)
					v.y=8.3f;
				else if(v.x<0 && v.x>-7.0f)
					v.y=-8.3f;
				rigidbody2D.velocity = v;
				print ("ByttX");
			}
			else{
				Vector2 v = rigidbody2D.velocity;
				v = -v;
				rigidbody2D.velocity = v;
			}
		}*/
	}
コード例 #13
0
	// Use this for initialization
	void Start () {
		myRigidBody = GetComponent<Rigidbody2D>();
		myRigidBody.AddRelativeForce(Vector3.right * projectileSpeed);
		myRigidBody.AddTorque(torque);
	}
コード例 #14
0
    // Use this for initialization
    void Start()
    {
        incol = false;
        invis = false;

        mainstate = GameObject.FindGameObjectWithTag ("GameController").GetComponent<GameController> ();

        curasteroidstate = GetComponentInParent<AsteroidManager> ();
        curRig = GetComponent<Rigidbody2D> ();

        // Scaling
        // Get main camera component
        main = Camera.main;
        // Main camera height and width
        camheight = main.orthographicSize * 2;
        camwidth = camheight * main.aspect;
        // Set temp to ship sprite
        temp = GetComponent<SpriteRenderer> ().sprite;
        // How big bg1 is in world units
        unitWidth = temp.textureRect.width / temp.pixelsPerUnit;
        //unitHeight = temp.textureRect.height / temp.pixelsPerUnit;

        // Asteroid Details
        randomscale = Random.Range (7, 12);
        speed.x = 0;
        speed.y = Random.Range (curasteroidstate.speedmin, curasteroidstate.speedmax);
        turnspeed = Random.Range (-4, 4);

        // Scale ship according to camera size
        transform.localScale = new Vector3 (camwidth / (unitWidth * randomscale), camwidth / (unitWidth * randomscale));

        //Asteroid Initial speeds
        curRig.velocity = speed;
        curRig.AddTorque (turnspeed);
    }
コード例 #15
0
ファイル: Thingy.cs プロジェクト: saltatory/unity-fsm
    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();

        // Create some states
        stateFree = AddState ("Free");
        stateCaptured = AddState ("Captured");
        stateFlushed = AddState ("Flushed");

        StartState.AddTransition (stateFree).AddTransition (stateCaptured).AddTransition (stateFlushed);

        // Get a list of all audio sources on children
        audioSources = new Dictionary<string, AudioSource> ();
        foreach (AudioSource s in GetComponentsInChildren<AudioSource> ()) {
            audioSources.Add (s.gameObject.name, s);
        }

        Transition (stateFree);

        // Apply a random velocity to the ball
        rb.velocity = new Vector2 (Random.value * 3, Random.value * 3);
        rb.AddTorque(Random.Range(1,3));
    }
コード例 #16
0
    private void Start()
    {
        _Rigidbody = GetComponent<Rigidbody2D>();
        float magnitude = Random.Range (MinForce, MaxForce);
        float x = Random.Range (-1f, 1f);
        float y = Random.Range (-1f, 1f);

        _Rigidbody.AddForce (magnitude * new Vector2 (x,y));

        float torque = Random.Range (MinTorque, MaxTorque);
        _Rigidbody.AddTorque (torque);

        // TO-DO: complete this class
    }