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