Unity的Mass、AddForce和碰撞、触发器

Mass质量  尽量0.1~10
Drag阻力,float,任意方向都受阻力
Use Gravity是否使用重力
Is kinematic是否遵循动力学
Collision Detection碰撞检测模式

1.AngularVelocity(角速度):表示刚体的角速度向量,数据类型为Vector3,该变量的方向既为刚体旋转轴方向,旋转方向遵循左手定则。
2.Velocity(位移速度):表示物体的位移速度值。
3.CenterOfMass(重心):通过调低物体的重心,可以使物体不因为其他物体的碰撞或者作用力而倒下。
4.DetectCollisions(碰撞检测开关):表示物体是否能够与其他物体产生碰撞效应。
5.InertiaTensor(惯性张量):描述物体转动惯量,类型为Vector3
using UnityEngine;
using System.Collections;

public class ro : MonoBehaviour {
    public float rorateSpeed = 90f;
    public float moveSpeed = 3f;
    // Use this for initialization
    void Start () {
        //GetComponent<Rigidbody> ().angularVelocity = Vector3.up * rorateSpeed;
        //GetComponent<Rigidbody> ().velocity = Vector3.forward * moveSpeed;
        GetComponent<Rigidbody> ().centerOfMass = Vector3.down * 0.5f;
        GetComponent<Rigidbody> ().detectCollisions = false;  //false不检测碰撞
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}


if (Input.GetKeyDown (KeyCode.Space)) {
            //ForceMode默认是Force,施加力时,受质量影响
            //GetComponent<Rigidbody>().AddForce(Vector3.up*300f,ForceMode.Force);

            //Acceleration忽略本身质量,按默认值1
            //GetComponent<Rigidbody> ().AddForce (Vector3.up * 100f,ForceMode.Acceleration);
            //VelocityChange 忽略质量
            GetComponent<Rigidbody> ().AddForce (Vector3.up* 300f, ForceMode.VelocityChange);
            //钢体某个位置施加力
            GetComponent<Rigidbody> ().AddForceAtPosition (Vector3.up* 300f,transform.position+new Vector3 (0.5f,-0.5f,0));
        }
        }


using UnityEngine;
using System.Collections;

public class CollisionSC : MonoBehaviour {
    public Collider red;
    public Collider blue;
    // Use this for initialization
    void Start () {
        //忽略两个碰撞器之间的碰撞,true,忽略,false,不忽略
        Physics.IgnoreCollision (red, blue, true);
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}
忽略两层碰撞器之间的碰撞,layers +两个层blue、red,将blue球都加到layout的blue层,同理红球。Edit-project Setting-Physics,blue和red的对勾取消。


//开始发生碰撞,参数是碰撞到的碰撞体
    void OnCollisionEnter(Collision other){
        Debug.Log (other.gameObject.name);
    }
    //碰撞中
    void OnCollisionStay(Collision other){
    
    }
    //碰撞结束
    void OnCollisionExit(Collision other){

    }

Is Trigger触发器,只触发方法,如碰撞功能等需要自己实现。
//触发器,碰撞时触发Enter方法
    void OnTriggerEnter(Collider other){
        Debug.Log (other.gameObject.name);
    }
    //碰撞中
    void OnTriggerStay(Collider other){

    }
    //碰撞结束
    void OnTriggerExit(Collider other){

    }


 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Star_MengMeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值