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


C# Rigidbody.AddForceAtPosition方法代碼示例

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


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

示例1: ApplyAntiRoll

    public void ApplyAntiRoll(Rigidbody rigidbody)
    {
        WheelHit hit = new WheelHit();
        float travelL = 1.0f;
        float travelR = 1.0f;

        bool groundedL = wheelL.collider.GetGroundHit(out hit);
        if (groundedL)
        {
            travelL = (-wheelL.collider.transform.InverseTransformPoint(hit.point).y - wheelL.radius) / wheelL.collider.suspensionDistance;
        }

        bool groundedR = wheelR.collider.GetGroundHit(out hit);
        if (groundedR)
        {
            travelR = (-wheelR.collider.transform.InverseTransformPoint(hit.point).y - wheelR.radius) / wheelR.collider.suspensionDistance;
        }

        float antiRollForce = (travelL - travelR) * antiRollValue;

        if (groundedL)
        {
            rigidbody.AddForceAtPosition(wheelL.collider.transform.up * -antiRollForce,
                                            wheelL.collider.transform.position);
        }

        if (groundedR)
        {
            rigidbody.AddForceAtPosition(wheelR.collider.transform.up * antiRollForce,
                  							 wheelR.collider.transform.position);
        }
    }
開發者ID:Gnork,項目名稱:proTRonDrive,代碼行數:32,代碼來源:AntiRoll.cs

示例2: PushRigidbody

 /// <summary>
 /// makes this controller push a rigidbody using force or fixed velocity
 /// depending on the supplied 'PushForceMode'. in the 'Simplified' mode
 /// the controller will directly set the velocity of the rigidbody.
 /// in the 'Kinetic' mode force will be applied to the rigidbody at point
 /// of contact, and will accumulate. NOTE: 'point' will only have effect
 /// in 'Kinetic' mode.
 /// </summary>
 public void PushRigidbody(Rigidbody rigidbody, Vector3 moveDirection, PushForceMode pushForcemode, Vector3 point)
 {
     switch (pushForcemode)
     {
         case PushForceMode.Simplified:
             rigidbody.velocity = (vp_3DUtility.HorizontalVector((new Vector3(moveDirection.x, 0, moveDirection.z)).normalized) * (PhysicsPushForce / rigidbody.mass));
             break;
         case PushForceMode.Kinetic:
             // if collision occurs beside (neither above nor below) the player we
             // will only apply horizontal force. this makes pushing stuff around
             // much smoother and easier
             if (Vector3.Distance(vp_3DUtility.HorizontalVector(Transform.position), vp_3DUtility.HorizontalVector(point)) > Player.Radius.Get())
             {
                 rigidbody.AddForceAtPosition(vp_3DUtility.HorizontalVector(moveDirection) * (PhysicsPushForce * KINETIC_PUSHFORCE_MULTIPLIER), point);
                 // DEBUG: uncomment this to visualize horizontal push RPCs as green balls
                 //GameObject o1 = vp_3DUtility.DebugBall();
                 //o1.renderer.material.color = Color.green;
                 //o1.transform.position = point;
             }
             else
             {
                 // if collision occured above or below the player we will apply force
                 // along the unmodified collision vector. this makes for more realistic
                 // physics when walking on top of stuff or bumping your head into it
                 rigidbody.AddForceAtPosition(moveDirection * (PhysicsPushForce * KINETIC_PUSHFORCE_MULTIPLIER), point);
                 // DEBUG: uncomment this to visualize vertical push RPCs as red balls
                 //GameObject o2 = vp_3DUtility.DebugBall();
                 //o2.transform.position = point;
             }
             break;
     }
 }
開發者ID:kendobi,項目名稱:Entropy_V5,代碼行數:40,代碼來源:vp_Controller.cs

示例3: Start

 // Use this for initialization
 void Start()
 {
     _rigidbody = gameObject.GetComponent<Rigidbody>();
     _rigidbody.AddForceAtPosition(Vector3.up * Random.Range( 400f,900f), Random.insideUnitSphere * 2);
 }
開發者ID:thelucre,項目名稱:unity-demos,代碼行數:6,代碼來源:CoinScript.cs

示例4: ApplyForce

 public IEnumerator ApplyForce(Rigidbody body)
 {
     yield return new WaitForSeconds(.4f);
     Vector3 direction = body.transform.position - transform.position;
     body.AddForceAtPosition(direction.normalized, transform.position);
 }
開發者ID:jsmulikow664,項目名稱:Zombie-Slaughter-FPS,代碼行數:6,代碼來源:ExplosionAdvanced.cs

示例5: ApplyForce

 void ApplyForce(Rigidbody body)
 {
     Debug.LogError("Wtf!");
     Vector3 direction = body.transform.position - transform.position;
     body.AddForceAtPosition(direction.normalized, transform.position);
 }
開發者ID:legotack,項目名稱:Frisbee-Game,代碼行數:6,代碼來源:clsurgentactuator.cs

示例6: ApplyKillForce

 public override void ApplyKillForce(Rigidbody rigidbody)
 {
     rigidbody.AddForceAtPosition(Force, Position, ForceMode.Impulse);
 }
開發者ID:bodedoctor,項目名稱:onslaught,代碼行數:4,代碼來源:PointKillForce.cs


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