当前位置: 首页>>代码示例>>C#>>正文


C# Rigidbody.AddForce方法代码示例

本文整理汇总了C#中UnityEngine.Rigidbody.AddForce方法的典型用法代码示例。如果您正苦于以下问题:C# Rigidbody.AddForce方法的具体用法?C# Rigidbody.AddForce怎么用?C# Rigidbody.AddForce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Rigidbody的用法示例。


在下文中一共展示了Rigidbody.AddForce方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    void Start()
    {
        bullet = this.GetComponent<Rigidbody>();
        bullet.AddForce(this.transform.forward *  thrust);

        GameObject.Destroy(this.gameObject, 3.0f);
    }
开发者ID:DarioDomiDE,项目名称:SwitchWitch,代码行数:7,代码来源:BulletMovement.cs

示例2: 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

示例3: Start

 // Use this for initialization
 void Start()
 {
     S = this;
     rb = GetComponent<Rigidbody>();
     rb.AddForce(Vector3.forward * 20);
     rb.AddForce(Vector3.up * 10);
     mouseXPos = 0;
 }
开发者ID:sspringg,项目名称:Rapid_Game_Prototype,代码行数:9,代码来源:Monkey.cs

示例4: Start

 void Start()
 {
     rigidbody = GetComponent<Rigidbody>();
     if(Application.loadedLevel == 2)
     rigidbody.AddForce(800000000, 0, 0);
     else
     rigidbody.AddForce(71000, 0, 0);
 }
开发者ID:Extreme112,项目名称:TomsCaveEscape,代码行数:8,代码来源:Giantboulder.cs

示例5: Start

    void Start()
    {
        sounds = GetComponents<AudioSource>();
        quack = sounds[0];

        rb = GetComponent<Rigidbody>();
        rb.AddForce(transform.forward * speed);
        rb.AddForce(transform.up * speed2);
    }
开发者ID:atb818,项目名称:Duck-Game,代码行数:9,代码来源:bulletLogic.cs

示例6: Awake

    void Awake()
    {
        //reference to rigidbody and transform for force appplication
        rigidbody = GetComponent<Rigidbody>();
        orbital = this.transform;

        //starting force
        rigidbody.AddForce(Vector3.left * speed);
        rigidbody.AddForce(Vector3.up * speed);
    }
开发者ID:btrowbridge,项目名称:Mesh_In_Unity,代码行数:10,代码来源:ParticleBehavior.cs

示例7: OnCollisionEnter

 void OnCollisionEnter(Collision col)
 {
     rb = GetComponent<Rigidbody>();
     if (col.gameObject.name.Contains("shield"))
     {
         rb.AddForce(col.gameObject.transform.forward * BounceStrength * -1);
     }
     else {
         rb.AddForce(col.gameObject.transform.forward * BounceStrength);
     }
 }
开发者ID:fbav,项目名称:locomotion,代码行数:11,代码来源:Ricochet.cs

示例8: Start

    // Use this for initialization
    void Start()
    {
        //bullets set to disappear after thirty seconds, rotate for prefab weirdness
        initialForce = 300;
        Destroy(this.gameObject, 30);
        transform.Rotate(90,0,0);

        //initial force only
        body = GetComponent<Rigidbody>();
        body.constraints = RigidbodyConstraints.FreezeRotationY;
        body.AddForce(transform.right * Random.Range(-deviation,deviation));
        body.AddForce(transform.up * initialForce);
    }
开发者ID:jzhangx2,项目名称:SpaceTown,代码行数:14,代码来源:bulletScript.cs

示例9: Start

    // Use this for initialization
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody>();

        int toss = Random.Range (1,3);
        switch(toss){
        case 1:
            myRigidbody.AddForce (-Vector3.right * 50, ForceMode.Impulse);
            break;
        case 2:
            myRigidbody.AddForce (Vector3.right * 50, ForceMode.Impulse);
            break;
        }
    }
开发者ID:Harley-Torrisi,项目名称:Net-Hocky,代码行数:15,代码来源:Puck_Move.cs

示例10: jump

 public static void jump(Rigidbody player, Vector3 force)
 {
     if (GameManager.Instance.ThePlayer.GetComponent<PlayerProperties>().CheckGroundDist())
     {
         player.AddForce(force);
     }
 }
开发者ID:abiaco,项目名称:ggj_2016,代码行数:7,代码来源:Action.cs

示例11: Start

    // Use this for initialization
    void Start()
    {
        if (directionRight)
        {
            direction = new Vector3(1.0f, 0.0f, 0.0f);
            offset = new Vector3(1.0f, 1.0f, 0.0f);
        }
        else
        {
            direction = new Vector3(-1.0f, 0.0f, 0.0f);
            offset = new Vector3(-2.0f, 1.0f, 0.0f);
        }

        if (!directionRight)
        {
            SpriteRenderer spriterenderer = gameObject.GetComponent<SpriteRenderer>();
            Vector3 scale = spriterenderer.transform.localScale;
            scale.x *= -1;
            spriterenderer.transform.localScale = scale;
        }

        gameObject.transform.position = player.gameObject.transform.position + offset;

        rigidBody = GetComponent<Rigidbody>();
        rigidBody.AddForce(direction * thrust, ForceMode.Impulse);
    }
开发者ID:c4tTi,项目名称:GGJ16,代码行数:27,代码来源:FeuerwerkMovement.cs

示例12: Update

    // Update is called once per frame
    void Update()
    {
        hero = GetComponent<Rigidbody> ();
        anim.SetBool("is_jump", !grounded);

        if (grounded && ((Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.Space)))) {
            hero.AddForce(new Vector3(0f, ForceJump, 0f));
            //soundJump.Play();
        }
        hero.velocity = new Vector3(move * MaxSpeed, hero.velocity.y, hero.velocity.z);

        if (move == 0) {
            anim.SetBool ("boolrun", false);
        }else
        {
            anim.SetBool("boolrun", true);
        }

        if (Input.GetKey (KeyCode.R)) {
            Application.LoadLevel(Application.loadedLevel);
        }

        if (facingRight && move < 0) {
            Flip();
        }
        else if(!facingRight && move > 0)
        {
            Flip();
        }
    }
开发者ID:YoGames,项目名称:SumoWrestling,代码行数:31,代码来源:HeroController.cs

示例13: Start

 // Use this for initialization
 void Start()
 {
     rb = GetComponent<Rigidbody> ();
     rb.AddForce (transform.forward * speed);
     // 弾丸が作成された位置がFirePosの位置と同じ
     firePos = transform.position;
 }
开发者ID:kwbt-mrokj,项目名称:S_Shooter01,代码行数:8,代码来源:BulletCtrl.cs

示例14: FixedUpdate

	// Update is called once per frame
    void FixedUpdate()
    {


        if (Input.GetKeyUp(KeyCode.Space))
        {
            if (!(jammersThrown == TotalJammers))
            {
                jammersThrown++;

                GameObject Clone = Instantiate(JammerGameObject);

                Clone.transform.position = JammerOrigin.position;

                jammerPhysics = Clone.GetComponent<Rigidbody>();



                jammerPhysics.useGravity = true;
                jammerPhysics.isKinematic = false;

                jammerPhysics.AddForce(transform.forward * 100);
            }
        }
    }
开发者ID:talhahasanzia,项目名称:MazeBot-Old-Unity5.0,代码行数:26,代码来源:JammerThrow.cs

示例15: handleCollision

 public bool handleCollision(ControllerColliderHit hit, Rigidbody body, float force)
 {
     Vector3 pushDir = new Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
     //		body.velocity = pushDir * force;
     body.AddForce (pushDir * force);
     return false;
 }
开发者ID:hannahjgb,项目名称:AdventureGameFiles,代码行数:7,代码来源:PlayerPushHandler.cs


注:本文中的UnityEngine.Rigidbody.AddForce方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。