Unity basic fixed joint FixedJoint

Unity is a powerful game development engine, which provides a variety of rich functions and components, enabling developers to easily create complex game worlds. Among them, Fixed Joint (FixedJoint) is a very important component in Unity, which is used to realize the fixed connection between objects.

 

 

Component main panel properties:

Connected Body A reference to the Rigidbody the joint depends on (optional). If not set, the joint is connected to the world.

Break Force: The force that needs to be applied to break this joint.

Break Torque: The torque that needs to be applied in order to break this joint.

Enable Collision: When this check box is checked, collisions between jointed connected bodies are allowed.

1. Overview of fixed joints 

Fixed Joint (FixedJoint) is a physical component in Unity, which is used to connect two objects together to make them a whole. A fixed joint is a rigid body joint (Rigidbody Joint), which can be set and controlled through code or the Unity editor. When an object is connected to another object through a fixed joint, they will maintain a fixed relative position and orientation, and will not be displaced or rotated by external forces.

Second, the principle of fixed joints 

The principle of a fixed joint is to achieve fixation by creating a virtual connection point between two objects. The position and direction of this connection point can be adjusted in the Unity editor, or dynamically set through code. The fixed joint calculates the relative displacement and rotation between two objects according to the position and direction of the connection point, and applies it to the rigid body component on the object, so as to realize the fixed connection between the objects.

3. How to use fixed joints 

In Unity, using fixed joints is very simple. First, make sure you have two objects in your scene that need to be connected, and that they both have rigidbody components. Then, set up the fixed joint as follows:

Select one of the objects and set the Is Kinematic property of its rigid body component to True. This will take the object out of the control of the physics engine and thus keep it stationary.

Select another object and set the Is Kinematic property of its rigid body component to False. This will put the object under the control of the physics engine and be able to collide and move with other objects.

In the Hierarchy view of the Unity editor, select the two objects that need to be connected.

In the Inspector view, click the "Add Component" button, and search for and add the FixedJoint component.

In the properties panel of the fixed joint component, you can set the position and direction of the connection point, as well as other parameters, and adjust them as needed.

Run the game, you will find that the two objects are fixedly connected together, keeping the relative position and direction unchanged.

Guess you like

Origin blog.csdn.net/qq_36592993/article/details/131813741