当前位置:网站首页>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 .


边栏推荐
- "Testing novice encyclopedia" 5-minute quick start pytest automated testing framework
- 大冤种们,新进测试行业,如何正确选择意向企业?
- MySQL 06 transaction, view, index, backup and recovery
- C#与Mysql数据库交互-Mysql配置及增删查改操作
- JS to realize simple form verification and select all functions
- Order timeout cancellation and commodity query by category
- 商品推荐和分类商品推荐
- SQL server stored procedures multi angle introduction suggestions collection
- Was not registered for synchronization because synchronization is not active[resolved]
- 文件的上传和下载
猜你喜欢

Leetcode first day of question brushing

商品评论信息与评论信息分类

JDBC MySQL 01 JDBC operation MySQL (add, delete, modify and query)

Kinect for Unity3d----KinectManager

Overview of Baidu map technology, and application development of basic API and webapi

Low noise anion fan touch IC

express get/post/delete...请求

Join query and subquery

IDEA连接数据库时区问题,报红Server returns invalid timezone. Need to set ‘serverTimezone‘ property.

微信支付及支付回调
随机推荐
Personal Center - order business process
NPM's ID card and dependence
Functions in JS and the use of DOM to obtain elements and event attributes
Selenium automated test interview questions family bucket
连接查询和子查询
Uploading and downloading of files
Nodejs 模板引擎ejs
Leetcode brushes questions the next day
normal distribution, lognormal distribution,正态随机数的生成
MySQL 04 advanced query (II)
Overview of Baidu map technology, and application development of basic API and webapi
Order timeout cancellation and commodity query by category
SSM integration
Here are all the MySQL interview questions you can't expect (the latest version of 2022)
JDBC MySQL 01 JDBC operation MySQL (add, delete, modify and query)
Product recommendation and classified product recommendation
Sentinel1.8.4 persistent Nacos configuration
MongoDB
I'm stupid. When completable future is used with openfegin, it even reports an error
ES6数值的扩展