当前位置: 首页>>代码示例>>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;未经允许,请勿转载。