本文整理汇总了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);
}
}
示例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;
}
}
示例3: Start
// Use this for initialization
void Start()
{
_rigidbody = gameObject.GetComponent<Rigidbody>();
_rigidbody.AddForceAtPosition(Vector3.up * Random.Range( 400f,900f), Random.insideUnitSphere * 2);
}
示例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);
}
示例5: ApplyForce
void ApplyForce(Rigidbody body)
{
Debug.LogError("Wtf!");
Vector3 direction = body.transform.position - transform.position;
body.AddForceAtPosition(direction.normalized, transform.position);
}
示例6: ApplyKillForce
public override void ApplyKillForce(Rigidbody rigidbody)
{
rigidbody.AddForceAtPosition(Force, Position, ForceMode.Impulse);
}