Unity physics engine

1. Definition
The physics engine is to simulate the real physical effect in the game.
2. Rigid body
Rigidbody (rigid body) component can make the game object move under the control of the physical system. Any game object can only be affected by gravity if the rigid body component is added.

Please add a picture description
3. Collision
Collider classification:
box collider Box Collider, spherical collider Sphere Collider,
capsule collider Capsule Collider, grid collider Mesh Collider,
wheel collider, etc.
Efficiency comparison:
spherical collider > capsule collider > box Collider > Mesh Collider
The necessary conditions for collision: two objects must have a collider; one object must have a rigid body.
4. Collision detection
1) Collider
a, the frame of the collision contact is called
void OnCollisionEnter(Collision collision) {}
b, each frame of the collision contact is called
void OnCollisionStay(Collision collision) { }
c, the end of the collision is called
void OnCollisionExit(Collision collision) { }
2) Trigger
The trigger can penetrate, so the gravity must be removed.
Is Trigger is ticked .
Use Gravity is canceled
insert image description here
a. The frame that triggers the contact is called
void OnTriggerEnter(Collider other) {}
c. Each frame that triggers the contact is called
void OnTriggerStay(Collider other) { }
d, the end of the trigger is called
void OnTriggerExit(Collider other) { }
4.
Tags Tags are tags in the Unity engine, and are attributes used to identify GameObjects. Tags are often used for a single GameObject.
insert image description here

//tag的用法
void OnTriggerEnter(Collider other)
	{
    
    
		if (other.tag == "Player")
		{
    
    
			print("碰到玩家");
		}
		if (other.tag.CompareTo("Player") == 0)
		{
    
    
			print("碰到玩家");
		}
		if (other.CompareTag("Player"))
		{
    
    
			print("碰到玩家");
		}		

Guess you like

Origin blog.csdn.net/weixin_44706943/article/details/126821073