unity twelve rigid body

I. Introduction Rigidbody rigid parameters.

Mass : the quality of
the Drag : the group. When subjected to air resistance when a force moving game objects. 0 means no air resistance, resistance is great game objects will immediately stop the movement.
The Drag Angulular : angle resistance. When the player object is controlled by the resistance force of the rotational torque. 0 means no air resistance, great resistance when the game object will immediately stop rotating.
Gravity the Use : Use gravity. If this is turned on, the game object is affected by gravity.
Kinematic IS : whether to open dynamics. If you turn on this parameter, then the object will not affect Rigidbody longer, and with no increase Rigidbody the same effect, only its operation through the Transform component properties. Scenario: can be coupled with a rigid body, the rigid body when it is not the time tick, and then remove the hook when required. For example, the elevator, go up when I put on the hook, use Transform the elevator to go up.
To Interpolate : interpolation. The jitter is used to control the movement of the rigid body, there are three options to choose from.

  1. None, no interpolation.
  2. Interpolate: interpolated. Based on the preceding frame of the smoothed Transform Transform
  3. Extrapolate: extrapolated. Transform based on the next frame to smooth the Transform.

Detection Collision : Collision Detection. This attribute is used to control game objects moving at high speed through other objects without collision, there are three options to choose from. Discrete default, the other two: Continous, Continuous Dynamic are continuous collision detection, for detecting the high-speed moving object, and finally detecting a maximum frequency.

Constraints: constraints. This controls the constraints for rigid body motion.

  1. Freeze Position: Freeze position. Rigid object in the world coordinate system X, Y, Z-axis direction movement invalid.
  2. Freeze Rotation: Freeze rotation. Rigid objects in the world coordinate system X, Y, and Z-axis rotation direction invalid.

Here Insert Picture Description

Rigid application

Learn to use AddForce method to add objects to add a rigid body forces.
AddForce has two parameters: 1, the direction of the force. 2, the mode of force (optional)
rigid follow anyone conservation of momentum ft = mv, mode of force described below with conservation of momentum about the courage of your convictions.
There are several models on the force:

  1. ForceMode.Force: default mode, add objects to a continuous force.
  2. ForceMode.Acceleration: Sustainable acceleration. It ignores the actual quality of rigid body and the default value 1.0f.
  3. ForceMode.Impulse: instant impact. The default value of t 1. Only one would have a force, and then not to force.
  4. ForceMode.VelocityChange: directly change the velocity magnitude, the default quality of 1.0, while the actual frame interval ignoring the system, the default interval 1.0

Which ForceMode.Force, ForceMode.Impulse with two more.
Write an example, with regard to this method.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DaPao : MonoBehaviour
{
    public GameObject pullet;

    public Transform pulletPosition;

    public int power=500;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
        if (Input.GetKeyDown(KeyCode.Space))
        {
           GameObject a  = Instantiate(pullet, pulletPosition.position,pulletPosition.rotation);
//            a.GetComponent<Rigidbody>().AddForce((Vector3.forward+Vector3.up)*power,ForceMode.Force);
            a.GetComponent<Rigidbody>().AddForce((Vector3.forward)*power,ForceMode.Force);
            Destroy(a,5);
        }
    }
}
Published 56 original articles · won praise 24 · views 30000 +

Guess you like

Origin blog.csdn.net/u014196765/article/details/91981279