本文整理汇总了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);
}
示例2: applyLinearForce
public void applyLinearForce(Rigidbody toBody, Vector3 desiredForce, bool relative)
{
if(relative)
toBody.AddRelativeForce (desiredForce, this.forceMode);
else
toBody.AddForce (desiredForce, this.forceMode);
}
示例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;
}
示例4: Start
void Start()
{
rigidbody = GetComponent<Rigidbody>();
if(Application.loadedLevel == 2)
rigidbody.AddForce(800000000, 0, 0);
else
rigidbody.AddForce(71000, 0, 0);
}
示例5: Start
void Start()
{
sounds = GetComponents<AudioSource>();
quack = sounds[0];
rb = GetComponent<Rigidbody>();
rb.AddForce(transform.forward * speed);
rb.AddForce(transform.up * speed2);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例10: jump
public static void jump(Rigidbody player, Vector3 force)
{
if (GameManager.Instance.ThePlayer.GetComponent<PlayerProperties>().CheckGroundDist())
{
player.AddForce(force);
}
}
示例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);
}
示例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();
}
}
示例13: Start
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody> ();
rb.AddForce (transform.forward * speed);
// 弾丸が作成された位置がFirePosの位置と同じ
firePos = transform.position;
}
示例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);
}
}
}
示例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;
}