当前位置:网站首页>Unity learning notes (rigid body physics collider trigger)
Unity learning notes (rigid body physics collider trigger)
2022-07-27 19:04:00 【Miracle Fan】
List of articles
1.Rigidbody- rigid body

1.Property
| Property: | Function: |
|---|---|
| Mass | The mass of the object , default quality ( Company ) |
| Drag | The air resistance to the motion of an object |
| Angular Drag | Torque caused by air damping when the object rotates |
| Use Gravity | Whether it is affected by gravity |
| Is Kinematic | If it conforms to dynamics , Then the object is not affected by the physical engine , It can only be changed by adjustment , But it can still interact with other rigid bodies , Generally used for testing . |
[SerializeField] private float _forceAmount = 100f;
//[SerializeField] Serialize fields for , Private fields can be displayed in unity Debug the engine
private Rigidbody _rigidbody;
// Start is called before the first frame update
void Start()
{
_rigidbody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))// Click the left mouse button once to execute
{
_rigidbody.AddForce(Vector3.up * _forceAmount);
}
}
2. Physical material

1.Property:
| Property: | Function: |
|---|---|
| Dynamic Friction | Dynamic friction , The value is usually in 0~1 Between , by 0 Means smooth plane |
| Static Friction | Static friction , Usually in 0~1 Between |
| Bounciness | Elasticity index ,0~1,0 There is no elasticity ,1 It is completely elastic , No loss of energy |
| Friction Combine | How to calculate friction when two colliding bodies collide |
| - Average | Choose the average of the two |
| - Minimum | Choose the minimum of both |
| - Maximum | Choose the maximum of both |
| - Multiply | Choose to multiply the two |
| Bounce Combine | Equate to Friction Combine |
2. The creation process

3. Collision

3.1 Edit Collider
You can modify the collider size , As long as you touch the collider, set the range , It will trigger OncollisionEnter() function

OncollisionEnter() The function is the function excited when the object collides .Material Physical material for collision body , You need to create and add by yourself .
private Renderer _renderer;
void Awake()
{
// Get the component renderer object
_renderer = GetComponent<Renderer>();
}
private void OnCollisionEnter(Collision collision)
{
Color randomlySelectedColor=GetRandomColor();
_renderer.material.color=randomlySelectedColor;
}
private Color GetRandomColor()
{
return new Color(
r:UnityEngine.Random.Range(0f,1f),
g:UnityEngine.Random.Range(0f,1f),
b:UnityEngine.Random.Range(0f,1f));
}
private void OnCollisionEnter(Collision collision)
{
Debug.Log("Impacted at" +collision.contacts[0].point);
float rayDrawDistance = 5f;
Debug.DrawRay(
collision.contacts[0].point,
collision.contacts[0].normal*rayDrawDistance,// Normal direction of contact point
Color.red,
1f);
}
4. Trigger
OnTriggerEnter() The function is when the object triggers Trigger The post excitation function of the object .
void Awake()
{
// Get the component renderer object
_renderer = GetComponent<Renderer>();
}
private void OnTriggerEnter(Collider other)
{
Color randomlySelectedColor = GetRandomColorWithAlpha();
_renderer.material.color = randomlySelectedColor;
}
private Color GetRandomColorWithAlpha()
{
return new Color(
r: UnityEngine.Random.Range(0f, 1f),
g: UnityEngine.Random.Range(0f, 1f),
b: UnityEngine.Random.Range(0f, 1f),
a:0.25f);
}
The following figure shows the settings Trigger Changes after ,Trigger Objects do not affect the motion of other objects .


边栏推荐
- C file and folder input / output stream code
- Selenium automated test interview questions family bucket
- 商品评论信息与评论信息分类
- Intelligent insomnia therapeutic instrument product dlt8p68sa Jericho
- Imitation thread deduction
- Low noise anion fan touch IC
- Netred RGB mirror light touch chip-dlt8s15b-jericho
- Multifunctional wireless remote control moxibustion instrument chip dltap703sd
- Led learning eye protection table lamp touch chip-dlt8t10s-jericho
- express get/post/delete...请求
猜你喜欢

Led with fan eye protection learning table lamp touch chip-dlt8s12a

web UI 自动化测试:Selenium 语法详解 史上最全

JDBC MySQL 02 data access and Dao mode

专项测试之「 性能测试」总结

Redis注解
![[wechat applet] project practice - lottery application](/img/08/1e8643c95ad7c2661a76f9c3a0c57d.png)
[wechat applet] project practice - lottery application

Bathroom with demister vanity mirror touch chip-dlt8t10s

`this.$emit` 子组件给父组件传递多个参数

LeetCode 刷题 第二天

进行接口测试时,连接数据库,对数据源进行备份、还原、验证操作
随机推荐
ES6数值的扩展
[wechat applet] project practice - lottery application
Acquisition data transmission mode and online monitoring system of vibrating wire wireless acquisition instrument for engineering instruments
Unity显示Kinect捕获的镜头
Examples of map search
CMD command
MySQL 01 关系型数据库设计
MicaZ+Tinyos学习笔记(1)
Docker - docker installation, MySQL installation on docker, and project deployment on docker
Nacos display service registration address error
WPS turns off annoying advertisements
JDBC-MySql 01 JDBC操作MySql(增删改查)
SSM integration
Runtimeerror: output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256] [error]
TypeScript安装
Hash、Set、List、Zset、BitMap、Scan
WORD 2007+使用技巧
Mini washing machine touch chip dlt8ma12ts Jericho
用Matlab生成适用于期刊及会议的图形- plot
MySQL create event execution task