Unity3d基础学习第4天

物理引擎

1.刚体

1.1 Rigibody属性

1.Mass质量 默认值1,大部分物理的Mass为0.1 ~10 float
2.Drag 阻力 任意方向都会收到阻力 float
3.Angular Drag 旋转阻力 float
4.Use Gravity 使用重力
5.Is Kinematic 是否遵循动力学
6.Interpolate 差值方式
7.Collision Detection 碰撞检测模式 防止速度过快而产生击穿现象
8.Constrains 约束条件 冰冻位置和旋转

1.2 Rigibody使用方法

1.2.1 添加位移速度
    this.GetComponent<Rigidbody> ().velocity =  Vector3.left * move; 
1.2.2 降低重心
    this.GetComponent<Rigidbody> ().centerOfMass = Vector3.down * 0.5f;  //  0 -0.5 0
1.2.3 碰撞检测开关
    this.GetComponent<Rigidbody> ().detectCollisions = false; 
1.2.4 添加旋转角速度
    this.GetComponent<Rigidbody> ().angularVelocity = Vector3.up * speed;
1.2.5 添加力
    this.GetComponent<Rigidbody> ().AddForce (Vector3.up * 400f);

1.ForceMode默认force 施加力时,受重力影响 慢慢加力
2.ForceMode.Acceleration 忽略本身质量。默认值1
3.ForceMode.VelocityChange 忽略质量
4.ForceMode.Impulse 以冲量的方式添加力 瞬间的作用力.

1.2.6 指定位置添加力
    this.GetComponent<Rigidbody>().AddForceAtPosition(Vector3.up*400f,transform.position +new Vector3 (0.5f, 0, 0.5f));

2.碰撞器

2.1 分类

1.盒子碰撞器
2.球体碰撞器
3.胶囊碰撞器
4.网络碰撞器
5.车轮碰撞器
6.地形碰撞器

2.2 使用方法

2.2.1 忽略碰撞
    public Collider red;
	public Collider blue;
	void Start () 
	{Physics.IgnoreCollision (red, blue,true);  //忽略碰撞}
2.2.2 碰撞的方法
    void OnCollisionEnter(Collision g)  //开始碰撞
	{
		Debug.Log ("开始碰撞"+g.gameObject.name);
	}
	void OnCollisionStay(Collision g)  //碰撞中
	{
		Debug.Log ("碰撞中"+g.gameObject.name);
	}
	void OnCollisionExit(Collision g)  //碰撞结束
	{
		Debug.Log ("碰撞结束" +g.gameObject.name);
	}
2.2.3 触发方法 在collider中Is Trigger 中勾选
    void OnTriggerEnter(Collider g)
	{
		Debug.Log ("触发开始" + g.gameObject.name);
	}
	void OnTriggerStay(Collider g)
	{
		Debug.Log ("触发中" + g.gameObject.name);
	}
	void OnTriggerExit(Collider g)
	{
		Debug.Log ("触发结束" + g.gameObject.name);
	}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值