當前位置: 首頁>>代碼示例>>C#>>正文


C# Rigidbody.AddRelativeForce方法代碼示例

本文整理匯總了C#中UnityEngine.Rigidbody.AddRelativeForce方法的典型用法代碼示例。如果您正苦於以下問題:C# Rigidbody.AddRelativeForce方法的具體用法?C# Rigidbody.AddRelativeForce怎麽用?C# Rigidbody.AddRelativeForce使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.Rigidbody的用法示例。


在下文中一共展示了Rigidbody.AddRelativeForce方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: applyLinearForce

 public void applyLinearForce(Rigidbody toBody, Vector3 desiredForce, bool relative)
 {
     if(relative)
         toBody.AddRelativeForce (desiredForce, this.forceMode);
     else
         toBody.AddForce (desiredForce, this.forceMode);
 }
開發者ID:rusticgames,項目名稱:rts,代碼行數:7,代碼來源:Mechanism.cs

示例2: Go

        void Go()
        {
            float throwForce = 0;
            //Aims grenade at Target
            if (hasTarget)
            {
                float xDist = Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(target.x, target.z));
                float yDist = -(transform.position.y - target.y);

                //Calculate force required
                throwForce = xDist / (Mathf.Sqrt(Mathf.Abs((yDist - xDist) / (0.5f * (-Physics.gravity.y)))));
                throwForce = 1.414f * throwForce / Time.fixedDeltaTime * GetComponent<Rigidbody>().mass;

                //Always fire on a 45 degree angle, this makes it easier to calculate the force required.
                transform.Rotate(-45, 0, 0);
            }
            myRigidBody = GetComponent<Rigidbody>();
            myRigidBody.AddRelativeForce(Vector3.forward * throwForce);

            //Start the time on the grenade
            StartCoroutine(StartDetonationTimer());
            //Because the grenade may skim the colliders of the agent before detonating, we want to wait a moment or two before being able to "warn" agents of the grenade
            //Warning will cause surrounding agents to attempt to escape from the grenade.
            StartCoroutine(SetTimeUntilWarning());
        }
開發者ID:SonGit,項目名稱:ProjectOracle,代碼行數:25,代碼來源:GrenadeScript.cs

示例3: Start

	// Use this for initialization
	void Start () {
//        gameController = GameControllerSingleton.get();
        rb = GetComponent<Rigidbody>();
        rb.AddRelativeTorque(0, initTorque, 0);
        rb.AddRelativeForce(0, initYForce, 0);
        initY = transform.position.y;
	}
開發者ID:rawrimryno,項目名稱:Zambio,代碼行數:8,代碼來源:PowerUpScript.cs

示例4: Start

 // Use this for initialization
 void Start()
 {
     FX = GetComponentInChildren<ParticleSystem> ();
     destroyTime = Time.time + lifeTime;
     rb = GetComponent<Rigidbody> ();
     rb.AddRelativeForce (Vector3.forward * FiredVel, ForceMode.VelocityChange);
 }
開發者ID:eeveelution,項目名稱:Wynnunity_Source,代碼行數:8,代碼來源:Projectile.cs

示例5: getHit

 public void getHit(Vector3 hitlocation)
 {
     rb = GetComponent<Rigidbody>();
     //use this for objects whos HIPS are oriented with Z axis going through them (dick to butt)
     //rb.AddRelativeForce(new Vector3(0,0,-1) * 3000);
     //use this for objects whos HIPs are oriented with Y axis going through them (dick to butt)
     rb.AddRelativeForce(new Vector3(0,-1,0) * 3000);
 }
開發者ID:zocheyado,項目名稱:GroundZero,代碼行數:8,代碼來源:GetTurnt.cs

示例6: FireNow

 void FireNow()
 {
     transform.rotation = originalRotation;
     transform.Rotate (Vector3.forward, Random.Range(-errorX,errorX));
     transform.Rotate (Vector3.right, Random.Range(-errorY,errorY));
     thisCannonball = Instantiate(cannonball, transform.position, transform.rotation) as Transform;
     thisRb = thisCannonball.GetComponent<Rigidbody>();
     thisRb.AddRelativeForce(Vector3.up * (shootForce + Random.Range(-errorForce,errorForce)));
     fireNow = false; // resets the button in Unity editor
 }
開發者ID:asmccormick,項目名稱:vive-catch,代碼行數:10,代碼來源:cannon.cs

示例7: UpdateJetPack

    void UpdateJetPack(float force, Rigidbody body, Transform fire)
    {
        if (force > 0)
            body.AddRelativeForce(Vector3.up * 5 * force);

        if (force == 0)
            fire.gameObject.GetComponent<MeshRenderer>().enabled = false;
        else
        {
            fire.gameObject.GetComponent<MeshRenderer>().enabled = true;
            fire.parent.localScale = new Vector3(1, force, 1);
        }
    }
開發者ID:brunobittarello,項目名稱:ProjectBoosters,代碼行數:13,代碼來源:JetPackControll.cs

示例8: Start

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

        myRigidBody.AddRelativeForce(fireForce * Vector3.forward);

        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,代碼行數:16,代碼來源:Bullet.cs

示例9: Start

	//public void AddForce(float x, float y, float z, ForceMode mode = ForceMode.Force);

	// Use this for initialization
	void Start() {
		//public void AddForce(float x, float y, float z, ForceMode mode = ForceMode.Force);
		rb = GetComponent<Rigidbody>();
		rb.AddRelativeForce(x * thrust, y * thrust, z * thrust);
	}
開發者ID:Staticjar,項目名稱:EH,代碼行數:8,代碼來源:InitialForce.cs

示例10: Start

	// Use this for initialization
	void Start () {

		rb = GetComponent<Rigidbody>();
		rb.AddRelativeForce (Vector3.forward * Force);
	}
開發者ID:sarernaja,項目名稱:1560700989_labunity,代碼行數:6,代碼來源:Bullet.cs

示例11: Start

	// Use this for initialization
	void Start () {
		rb = GetComponent<Rigidbody>();
		rb.AddRelativeForce(Vector2.up * force);
		Destroy(gameObject, lifetime);
	}
開發者ID:JChan106,項目名稱:HACKPOLY16,代碼行數:6,代碼來源:Bullet.cs

示例12: jettisonComponent

 private void jettisonComponent(Rigidbody component, Vector3 forceVector)
 {
     component.useGravity = true;
     component.collider.isTrigger = true;
     component.constraints = RigidbodyConstraints.None;
     Vector3 force = transform.InverseTransformDirection(forceVector);
     force.x = 0;
     float originalZ = force.z;
     float zComponent = Random.Range(force.z - 120f, force.z + 120f);
     force.z = zComponent;
     component.transform.Rotate(transform.right, (zComponent - originalZ)/2f);
     component.AddRelativeForce(force, ForceMode.Impulse);
     barrierComponents.Remove(component);
 }
開發者ID:piinecone,項目名稱:prototype3,代碼行數:14,代碼來源:Barrier.cs

示例13: 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

示例14: Start

 // Use this for initialization
 void Start()
 {
     rb = GetComponent<Rigidbody>();
     //	rb.AddForce(0, 0, speed);
     rb.AddRelativeForce(0, 0, speed);
 }
開發者ID:Reesy,項目名稱:Unity_breakout,代碼行數:7,代碼來源:BallController.cs

示例15: Start

 void Start()
 {
     rb = GetComponent<Rigidbody>();
     rb.AddRelativeForce(Vector3.right * thrust);
 }
開發者ID:aytona,項目名稱:GAME2005,代碼行數:5,代碼來源:addVelocity.cs


注:本文中的UnityEngine.Rigidbody.AddRelativeForce方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。