当前位置: 首页>>代码示例>>C#>>正文


C# Rigidbody.AddTorque方法代码示例

本文整理汇总了C#中UnityEngine.Rigidbody.AddTorque方法的典型用法代码示例。如果您正苦于以下问题:C# Rigidbody.AddTorque方法的具体用法?C# Rigidbody.AddTorque怎么用?C# Rigidbody.AddTorque使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Rigidbody的用法示例。


在下文中一共展示了Rigidbody.AddTorque方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

 // Use this for initialization
 void Start()
 {
     rb = GetComponent<Rigidbody> ();
     rb.AddForce ((Vector3.up * upVelocity) + (Vector3.left * Random.Range (-pushAmt, pushAmt)) + (Vector3.forward * Random.Range (-pushAmt, pushAmt)));
     rb.AddTorque (Vector3.up * Random.Range (-turnAmt, turnAmt));
     rb.AddTorque (Vector3.left * Random.Range (-turnAmt, turnAmt));
 }
开发者ID:ianburnette,项目名称:IslandFox,代码行数:8,代码来源:PushRigidbody.cs

示例2: Start

 void Start()
 {
     if(useRigidbody){
         rigidbody = GetComponent<Rigidbody>();
         rigidbody.AddTorque(transform.up * torque * (int)turnDirection);
     }
 }
开发者ID:redhandedgamer,项目名称:unity_bamboo,代码行数:7,代码来源:Rotator.cs

示例3: Start

 void Start()
 {
     rb = GetComponent<Rigidbody>();
     rb.maxAngularVelocity = 1000;
     rb.AddTorque(0, speed, 0);
     StartCoroutine(PerdaVelocidade());
 }
开发者ID:RockatanskyV8,项目名称:bp1_T,代码行数:7,代码来源:ObjectPhysics.cs

示例4: applyAngularForce

 public void applyAngularForce(Rigidbody toBody, Vector3 desiredTorque, bool relative)
 {
     if(relative) {
         toBody.AddRelativeTorque(desiredTorque, this.angularForceMode);
     }
     else {
         toBody.AddTorque(desiredTorque, this.angularForceMode);
     }
 }
开发者ID:rusticgames,项目名称:rts,代码行数:9,代码来源:Mechanism.cs

示例5: Shoot

    void Shoot()
    {
		var rotation = Quaternion.AngleAxis (90f, Vector3.forward);
		GameObject NuevaBala = Instantiate(balloon, source.transform.position, rotation) as GameObject;
        NuevaBala.transform.LookAt(MousePos);
        rb = NuevaBala.GetComponent<Rigidbody>();
        rb.AddForce(    torreta.transform.forward * ShootForce);
		rb.AddTorque (Vector3.right * ShootForce);
        Destroy(NuevaBala, 5);

    }
开发者ID:vicktor1805,项目名称:VallyGame,代码行数:11,代码来源:Turret.cs

示例6: Start

    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody>();

        //rbc = GameObject.Find("redbloodCell");
        // add random torque to the RBC so that it is spinning slightly
        float tX = Random.Range(-5.0f, 5.0f);
        float tY = Random.Range(-5.0f, 5.0f);
        float tZ = Random.Range(-5.0f, 5.0f);
        Vector3 newTorque = new Vector3 (tX, tY, tZ);
        rb.AddTorque(newTorque);

        Destroy(gameObject, 20);
    }
开发者ID:SamiHamid,项目名称:Into-The-Human-Body-MOBILE,代码行数:15,代码来源:rbcScript.cs

示例7: Start

    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody>();

        wbc = GameObject.Find("whiteBloodCell");
        //returningPoint = GameObject.FindGameObjectWithTag("returningPoint");
        //forceAreaReturn = GameObject.FindGameObjectWithTag("forceAreaReturn");

        // add random torque to the WBC so that it is spinning slightly
        float tX = Random.Range(-5.0f, 5.0f);
        float tY = Random.Range(-5.0f, 5.0f);
        float tZ = Random.Range(-5.0f, 5.0f);
        Vector3 newTorque = new Vector3(tX, tY, tZ);
        rb.AddTorque(newTorque);
    }
开发者ID:SamiHamid,项目名称:Into-The-Human-Body-MOBILE,代码行数:16,代码来源:wbcScript.cs

示例8: Start

    // Use this for initialization
    void Start()
    {
        if (directionRight)
        {
            direction = new Vector3(-1.0f, 1.0f, 0.0f);
            offset = new Vector3(1.0f, 2.0f, 0.0f);
        } else
        {
            direction = new Vector3(1.0f, 1.0f, 0.0f);
            offset = new Vector3(-2.0f, 2.0f, 0.0f);
        }

        gameObject.transform.position = player.gameObject.transform.position + offset;

        rigidBody = GetComponent<Rigidbody>();
        rigidBody.AddForce(direction * thrust, ForceMode.Impulse);
        rigidBody.AddTorque(new Vector3(0, 0, rotation), ForceMode.Impulse);
    }
开发者ID:c4tTi,项目名称:GGJ16,代码行数:19,代码来源:BrautstraussMovement.cs

示例9: Start

    // Use this for initialization
    void Start()
    {
        myRigidBody = GetComponent<Rigidbody>();
        myNetworkView = GetComponent<NetworkView>();
        myNetworkManager = Camera.main.GetComponent<NetworkManager>();

        myRigidBody.maxAngularVelocity = topAngularSpeed;
        myRigidBody.AddRelativeForce(fireForce * Vector3.forward);
        myRigidBody.AddRelativeForce(Random.Range(-fireRandomForce, fireRandomForce) * Vector3.right);
        myRigidBody.AddTorque(Random.Range(-fireRandomTorque, fireRandomTorque) * Vector3.up);
        transform.Rotate(Vector3.up, Random.Range(-fireRandomAngle, fireRandomAngle));

        if (!myNetworkManager.multiplayerEnabled || myNetworkView.isMine)
        {
            myTarget = new GameObject("Target");
            myTarget.transform.position = Camera.main.GetComponent<ControlsHandler>().mousePosition;
            myTarget.transform.parent = Camera.main.GetComponent<ControlsHandler>().target;
        }
    }
开发者ID:hongaaronc,项目名称:IntermediateGame,代码行数:20,代码来源:Missile.cs

示例10: RotateRigidbody

    /// <summary>
    /// Rotates the rigidbody.
    /// </summary>
    /// <returns>
    /// True if rigid body is successfully rotated.
    /// </returns>
    /// <param name='id'>
    /// Touch id.
    /// </param>
    /// <param name='torqueScalar'>
    /// Scalar value applied to torque calculation.
    /// </param>
    /// <param name='rigidbody'>
    /// Rigid body to rotate.
    /// </param>
    public static bool RotateRigidbody(int id, float torqueScalar, Rigidbody rigidbody)
    {
        bool success = false;

        Vector3 axis;

        float torque;

        if (TouchManager.RotationAxisTorque(id, torqueScalar, out axis, out torque))
        {

            rigidbody.AddTorque(axis * torque);

            success = true;
        }

        return success;
    }
开发者ID:verneh,项目名称:ARFight,代码行数:33,代码来源:TouchManager.cs

示例11: Update

    // Update is called once per frame
    void Update()
    {
        //update text and timers
        textOutput.text = count.ToString();
        timeSinceClick += Time.deltaTime;

        //check for object destruction
        if (selected)
        {
            if (selectedObj == null)
            {
                selected = false;
                return;
            }
            else
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                selectedObj.transform.position = ray.GetPoint(distToMaintain);
            }
        }

        if (Input.GetMouseButton(0))
        {
            if (!selected)
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] hits = Physics.RaycastAll(ray);

                foreach (RaycastHit hit in hits)
                {
                    if (hit.collider.gameObject.tag == "Resource")
                    {
                        selected = true;
                        selectedObj = hit.collider.gameObject;
                        selectedRigidbody = selectedObj.GetComponent<Rigidbody>();
                        selectedRigidbody.useGravity = false;
                        selectedRigidbody.AddTorque(selectedObj.transform.position.normalized * 7);
                        distToMaintain = Vector3.Distance(selectedObj.transform.position, Camera.main.transform.position);

                        break;
                    }
                }
            }
        }
        else
        {
            if (selected)
            {
                selectedRigidbody.useGravity = true;
                selectedRigidbody.AddForce(Vector3.down * fallForce);

                if (timeSinceClick <= clickTime)
                {
                    Destroy(selectedObj);
                    count++;
                }
            }

            selected = false;
            timeSinceClick = 0.0f;
        }
    }
开发者ID:apleshak,项目名称:Copy-for-Sasha,代码行数:63,代码来源:ResourceManager.cs

示例12: Start

	/// <summary>
	/// 
	/// </summary>
	protected virtual void Start()
	{

		m_Transform = transform;
		m_Rigidbody = rigidbody;
		m_Audio = audio;

		if (Camera.main != null)
			m_CameraMainTransform = Camera.main.transform;

		// set the main collider of this gameobject to be a trigger
		collider.isTrigger = true;

		// some default audio settings
		m_Audio.clip = PickupSound;
		m_Audio.playOnAwake = false;
		m_Audio.minDistance = 3;
		m_Audio.maxDistance = 150;
		m_Audio.rolloffMode = AudioRolloffMode.Linear;
		m_Audio.dopplerLevel = 0.0f;

		// store the initial position
		m_SpawnPosition = m_Transform.position;
		m_SpawnScale = m_Transform.localScale;
		RespawnScaleUpDuration = (m_Rigidbody == null) ? Mathf.Abs(RespawnScaleUpDuration) : 0.0f;

		// give bob a random start offset if value is not set
		if (BobOffset == -1.0f)
			BobOffset = Random.value;

		if (RecipientTags.Count == 0)
			RecipientTags.Add("Player");

		if (RemoveDuration != 0.0f)
			vp_Timer.In(RemoveDuration, Remove);

		if (m_Rigidbody != null)
		{
			if(RigidbodyForce != Vector3.zero)
				m_Rigidbody.AddForce(RigidbodyForce, ForceMode.Impulse);
			if(RigidbodySpin != 0.0f)
				m_Rigidbody.AddTorque(Random.rotation.eulerAngles * RigidbodySpin);
		}
	}
开发者ID:Barthuc,项目名称:ProjectLevelDesign,代码行数:47,代码来源:vp_Pickup.cs

示例13: Launch

 public void Launch(Rigidbody toLaunch)
 {
     toLaunch.isKinematic = false;
     toLaunch.AddForce (forceToPush * forceMult);
     toLaunch.AddTorque (forceToPush * forceMult);
     toLaunch.gameObject.GetComponent<Animator> ().SetTrigger ("shrink");
 }
开发者ID:ianburnette,项目名称:IslandFox,代码行数:7,代码来源:mainMenuGM.cs

示例14: SetRandomTorque

 public static void SetRandomTorque(Rigidbody rb, float maxTorque)
 {
     Vector3 randomTorque = maxTorque * Random.insideUnitSphere;
     rb.angularVelocity = Vector3.zero;
     rb.AddTorque(randomTorque);
 }
开发者ID:antfarmar,项目名称:Unity-3D-Asteroids,代码行数:6,代码来源:LotsOfUtils.cs

示例15: Update

    void Update()
    {
        facingDirection = script.GetFacingDirection ();

        // Throw Shuriken left or right
        if (amountUsed < 4) {
            if (Input.GetKeyDown (KeyCode.I)) {
                Clone = Instantiate (ShurikenPrefab, new Vector3 (spawnThrow.transform.position.x, spawnThrow.transform.position.y, -3.0f),
                                     	  Quaternion.identity) as Rigidbody;
                textObject = Instantiate (TextControlPrefab,
                                          new Vector3 (Clone.transform.position.x - 0.414f, Clone.transform.position.y + 0.352f, -3.0f),
                                          Quaternion.identity) as GameObject;

                // get first open slot
                for (int i = 0; i < Max; i++) {
                    if (shurikens [i] == null) {
                        shurikens [i] = Clone.transform;

                        textControl [i] = textObject.GetComponent<TextMesh> ();     // get the TextMesh
                        textControl [i].text = "O HOLD O";    // set initial so compiler doesnt complain
                        textPositions [i] = textObject.GetComponent<Transform> ();  // get its position

                        teleportBlast [i] = Clone.GetComponent<ParticleSystem> ();  // get its particle system

                        shurikenScripts [i] = Clone.GetComponent<ShurikenController> ();  // get its script
                        shurikenScripts [i].SetPlaced (false);

                        // Assign it the appropriate tag
                        if (i == 0)
                            Clone.gameObject.tag = "Shuriken0";
                        else if (i == 1)
                            Clone.gameObject.tag = "Shuriken1";
                        else if (i == 2)
                            Clone.gameObject.tag = "Shuriken2";
                        else if (i == 3)
                            Clone.gameObject.tag = "Shuriken3";

                        break; // found empty slot
                    }
                }
                if (facingDirection == Vector2.right) {  			// Throw to the right
                    Clone.AddForce (speed * new Vector3 (1.0f, 0.0f, 0.0f));
                    Clone.AddTorque (new Vector3 (0, 0, -turnSpeed));
                } else {    										// Throw to the left
                    Clone.AddForce (speed * new Vector3 (-1.0f, 0.0f, 0.0f));
                    Clone.AddTorque (new Vector3 (0, 0, turnSpeed));
                }
                amountUsed++;
            }
            // Place Shuriken at feet
            else if (Input.GetKeyDown (KeyCode.J)) {
                Clone = Instantiate (ShurikenPrefab, new Vector3 (spawnPlace.transform.position.x, spawnPlace.transform.position.y, -3.0f),
                                     	  Quaternion.identity) as Rigidbody;
                textObject = Instantiate (TextControlPrefab,
                                          new Vector3 (Clone.transform.position.x - 0.414f, Clone.transform.position.y + 0.352f, -3.0f),
                                          Quaternion.identity) as GameObject;

                // get first open slot
                for (int i = 0; i < Max; i++) {
                    if (shurikens [i] == null) {
                        shurikens [i] = Clone.transform;

                        textControl [i] = textObject.GetComponent<TextMesh> ();     // get the TextMesh
                        textControl [i].text = "O HOLD O";    // set initial so compiler doesnt complain
                        textPositions [i] = textObject.GetComponent<Transform> ();  // get its position

                        teleportBlast [i] = Clone.GetComponent<ParticleSystem> ();  // get its particle system

                        shurikenScripts [i] = Clone.GetComponent<ShurikenController> ();  // get its script
                        shurikenScripts [i].SetPlaced (true);   // this shuriken does not move

                        // Assign it the appropriate tag
                        if (i == 0)
                            Clone.gameObject.tag = "Shuriken0";
                        else if (i == 1)
                            Clone.gameObject.tag = "Shuriken1";
                        else if (i == 2)
                            Clone.gameObject.tag = "Shuriken2";
                        else if (i == 3)
                            Clone.gameObject.tag = "Shuriken3";

                        break; // found empty slot
                    }
                }
                amountUsed++;
            }
        }

        // update Text positions so they allign with shurikens
        for (int i = 0; i < Max; i++)
            if (shurikens [i] != null) {
                textPositions [i].position = new Vector3 (shurikens [i].position.x - 0.414f, shurikens [i].position.y + 0.352f, -3.0f);

                // is has parent then position it above it
                if (shurikens [i].parent != null)
                    textPositions [i].position += new Vector3 (0.0f, 1.0f, 0.0f);

                // if Enemy on Shuriken Position it below
                if (shurikenScripts [i].GetEnemyOnPlaced () != null)
                    textPositions [i].position -= new Vector3 (0.0f, 0.75f, 0.0f);
//.........这里部分代码省略.........
开发者ID:Archimedyz,项目名称:COMP_376_Project,代码行数:101,代码来源:ShurikenSpawner.cs


注:本文中的UnityEngine.Rigidbody.AddTorque方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。