Unity — Physics Engine —- RigidBody with collider

Time:2024-6-14

Unity --- Physics Engine ---- RigidBody with collider

 Unity --- Physics Engine ---- RigidBody with collider

1. The purpose of a RigidBody is to give an object physical properties (such as gravity, sassafras, etc.)

2. If we want the object to be able to collide with other objects, we need one more component — the Colider collider component.Unity --- Physics Engine ---- RigidBody with collider

1. The image above shows the collider components provided in Unity with various shapes already prepared.

2. The number of faces needed to form different shapes of colliders is different, the fewer the number of faces the less performance consumption when simulating a collision, generally in a 3d scene in order to save performance, we are choosing Box (cube) collidersUnity --- Physics Engine ---- RigidBody with collider

1. center is the center coordinate of the collider, and size is the size setting of the collider — for the box colider, the three values of size correspond to the length x width z height y

2. If you don’t want to control the shape, position and size of the collider through numerical values, you can also click Edit Colider to adjust the position and shape of the collider directly in the scene.Unity --- Physics Engine ---- RigidBody with collider

1. In addition to using set shapes as colliders, Unity also provides an “adaptive” collider, the Mesh Collider.

2. Pass the collider the material of the object and the mesh of the corresponding model of the object, and the collider will automatically generate a collision box that fits the object model.

Unity --- Physics Engine ---- RigidBody with collider

1. The above is the mesh of the model corresponding to the object.

2. The collider component will automatically get the mesh of the object’s corresponding model and assign it to the mesh in the component when it is attached to that object (of course, it can be changed as well).

3. The best collision simulation can be achieved with this component, however! The price is that this approach is very performance intensive!Unity --- Physics Engine ---- RigidBody with collider

1. convex — adj. prominent

2. Is there a way to get better crash results and still have better performance?

The answer is yes: just select Convex (sharp) in Mesh Colider — the generation of collision frames will be changed after selecting it — first, the collision frames will still be generated according to the faces of the model corresponding to the object, and then the points on the faces will be connected according to a certain pattern to get a simplified sharp collision frame.Unity --- Physics Engine ---- RigidBody with collider

After sharpening the collision box we are able to obtain a simplified version of it – this simplified version sacrifices some collision effects, but gains a large performance boost (and the sacrificed collision effects are still within acceptable limits)

2. If you use Mesh collider without Convex, Unity will not simulate the collision effect (Unity’s internal rules). If you go straight to Convex, it will lead to too many detecting surfaces of the collision box, which makes the simulation of collision effect very performance consuming — after using Convex, you can reduce the number of surfaces of the collision box — thus we can get better performance while guaranteeing a certain collision effect. — This in turn allows us to get better performance while maintaining a certain level of collision effect.

3. Generally the Mesh Collider collision box is the last option — it works great, but it’s just too performance intensive!


Introduction to the values of properties related to rigid bodies and colliders

Unity --- Physics Engine ---- RigidBody with collider

1. mass – mass – range of values of mass belowUnity --- Physics Engine ---- RigidBody with collider

If there is only one game object in the scene, it doesn’t matter what the mass is, but when there are multiple game objects in the scene, we need to set the mass of each game object accordingly — after all, you can’t make a rock weigh as much as a feather, right?Unity --- Physics Engine ---- RigidBody with collider

2. The second attribute, drag, is drag (damping) — this refers to air resistance.

The following graph has reference values for setting the air resistance property

Unity --- Physics Engine ---- RigidBody with collider

 Unity --- Physics Engine ---- RigidBody with collider

1. Interpolation can be set to mitigate the jitter generated by rigid body motion, and there are two forms of interpolation — internal and external interpolation — the difference between internal and external interpolation is that — each of them mitigates the jitter generated by rigid body motion in a different way.Unity --- Physics Engine ---- RigidBody with collider

1. The pattern of collision detection goes from top to bottom — the frequency of detection is getting bigger and bigger and the performance consumption is getting bigger and biggerUnity --- Physics Engine ---- RigidBody with collider

1. This constraint is only triggered when a collision occurs between rigid bodies.Unity --- Physics Engine ---- RigidBody with collider

1. After turning off Use Gravity, objects are not affected by gravity, but still have other physical properties!

2. Rigid body components and collider componentsThey generally appear in pairs, as the process by which game objects interact with other game objects and simulate the corresponding physical effects is:

a. Detect the collision by the collider component — Send the result to the rigid body component — Rigid body component simulate the corresponding physical effect by the result.

That is to say — if there is no collider component but only a rigid body component, the game object will still have physics but it will not be able to detect collisions and will just pass through other game objects without interacting with them.

3. The physics simulation of game objects with rigid body components is not always in progress, the algorithm will turn off the rigid body components of the object when the object is stationary, and only turn on the rigid body components of the object when the object is in motion to calculate the physics effects — to save game performance in this way.

4. Game objects that come into contact with each other with only the collider component working will only return collision results and then pass through each other (there is no rigid body component working to simulate the results of physics effects)Unity --- Physics Engine ---- RigidBody with collider

1. If Is Kinematic is checked, the effect that can be realized is — the game object has no physical characteristics, but still has rigid body characteristics — that is, after colliding with other game objects that have rigid body components for collision detection, the other game objects simulate the physical effect, and can be knocked away by the force instead of passing through, and the object itself is not affected by any force, and does not take place. movement

2. The Rigid Body Component accomplishes two things — a. It makes objects “solid” without being able to pass through or be passed through as a ghost.

b. To make objects have physical properties (referring to the various forces on an object, realized through physics engine simulations)

3. Collision box – internal logic of the rigid body component:

a. An object a moving — Is Kinematic turned on in the Rigid Body component — If it is turned on, then it has no physical properties (not acted upon by forces) but is just solid — If it is not turned on, then it has physical properties, is acted upon by forces, and the physics engine starts to simulate the physical effect.

b. Collision with other game object b (b is stationary) during motion — first b has no collision box (collider), if not no collision detection, try for the front did not collide, through the — if so, collision detection and return the result to the rigid body component —

If the rigid body component has physical properties then it starts to simulate the physical effects, otherwise it continues to squeeze the object b but does not go through it

Recommended Today

Python Pinball Game

======== Make a game for your little sister at school to play: . The game of marbles is largely determined by the coordinates xy, the length of the splice plate, and the radius of the ball: # -*- coding: utf-8 -*- # @Author : Codeooo # @Time : 2022/04/29 import sys import time import random […]