本文整理汇总了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);
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
示例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
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例10: Start
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
rb.AddRelativeForce (Vector3.forward * Force);
}
示例11: Start
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
rb.AddRelativeForce(Vector2.up * force);
Destroy(gameObject, lifetime);
}
示例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);
}
示例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;
}
}
示例14: Start
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody>();
// rb.AddForce(0, 0, speed);
rb.AddRelativeForce(0, 0, speed);
}
示例15: Start
void Start()
{
rb = GetComponent<Rigidbody>();
rb.AddRelativeForce(Vector3.right * thrust);
}