[Introduction to Unity] 23. Simple physics system

[Getting Started with Unity] Simple Physics System

    Hello everyone, I am Lampard~~

    Welcome to the Unity Getting Started series of blogs. The knowledge I have learned comes from Teacher Afa at Station B~Thanks 

 

(1) Gravity system

(1) Rigidbody component

    Unity provides physics system components that meet our conventional cognition. We can use these components to achieve some physical effects. For example, today we plan to realize the gravity effect of objects and use the Rigidbody component.

The Rigidbody component is a physics component in Unity that simulates the physical behavior of game objects. When a game object contains Rigidbody components, it can be affected by physical effects such as gravity, collision, force, torque, etc., such as being ejected, thrown, pushed, etc.

The Rigidbody component has several commonly used properties and methods, including:

- mass: The mass of the game object.

- velocity: The velocity of the game object.

- angularVelocity: The angular velocity of the game object.

- AddForce: apply a force to the game object, etc.

    Not much to say, let's hang this component on a random basketball to try the effect

    First of all, we created a basketball and a piece of grass in the scene. When we saw this basketball, we would think of singing and dancing Rap... Ah, sorry, we went to the wrong set

    In short, it is very unscientific. A basketball is actually in the sky, and then we will try to add Rigidbody components to it.

    Great, now the basketball is free falling 

(2) Collider

    The current effect is that it can fall straight, but we still need to make the basketball stop when it touches the grass to be more logical

    If it is written in code, we can judge the distance between these two objects, but the physics system of unity provides a more convenient collision detection mechanism, which is to provide various Collider components to detect collision requirements

There are the following Collider components in Unity:

1. Box Collider (Box Collider): A rectangle-based collision body used to simulate the collision of cuboid or cubic objects.

2. Sphere Collider: A sphere-based collider for simulating the collision of spherical objects.

3. Capsule Collider (Capsule Collider): A capsule-shaped collision body used to simulate the collision of certain capsule-shaped objects, such as characters.

4. Mesh Collider (Mesh Collider): A collision body based on the game object model, used to simulate the collision of objects with complex geometric shapes, such as terrain, buildings, etc.

5. Terrain Collider (terrain collider): a collision body based on Unity terrain, used to simulate the collision of terrain.

6. Wheel Collider (Wheel Collider): A collision body specifically for vehicles, used to simulate the collision between the wheels of the vehicle and the ground.

7. Character Controller: A collider specially designed for characters, used to simulate the movement and collision of characters.

    These Collider components can be selected and used according to the shape and needs of the game object . Now we only need to add a Box Collider cube-shaped collider to the grass and a Sphere Collider spherical collider to the basketball.

     Then look at the effect, you can indeed detect the collision

 

Alright, that's all for today, thank you all for reading! ! !
Like and follow! ! !

Guess you like

Origin blog.csdn.net/cooclc/article/details/130460176