"Unity" chapter 11th third-person character controller and collision body

Source: Internet
Author: User

Categories: Unity, C #, VS2015

Date Created: 2016-05-02 I. INTRODUCTION

The related concepts involved in the third person view controller are:

1, rigid body (rigidbody).

2, Collision Body (Collider). Includes Sphere Collider (Sphere Collider), Box Collider (Box Collider), Mesh collision body (mesh Collider), physical material (Physics Material), hinge Joint (Hinge Joint), Spring Joint ( Spring Joint) and so on.

Unity has built-in the NVIDIA PhysX physics engine. To control a physical object in a scene, simply add a rigid body (rigidbody) to the object. When you do this, the object is affected by gravity, and it can also be used for collision detection with other objects in the world coordinate system. Ii. key points of this chapter

1. Rigid body

A rigid body (rigidbody) is an object that is physically simulated. You can use a rigid body (rigidbody) for things that a player can push around (such as crates or loose objects), or to apply force to a rigid body (rigidbody) by writing a script to move it directly.

If you transform a non-kinematic rigid body (non-kinematic rigidbody), it may not collide correctly with other objects, so you should move it by applying force and torque to the rigid body (rigidbody). In addition, you can add joints (Joint) to a rigid body (rigidbody) to make the behavior more complex. For example, you can create a crane with a physical door, or a hoist with a swinging chain.

You can also use a rigid body (rigidbody) to make your vehicle appear vivid, such as using a rigid body, four wheel collider (Wheel Collider), and a script based on user input to apply wheel rotation force to create a car.

You can create an airplane by applying force to a rigid body (rigidbody) from a script.

Rigid bodies (Rigidbody) are most commonly used in conjunction with Primitive Collider (Primitive Collider).

Important NOTES:

    • The parent Hetska body (rigidbody) should never be used together
    • The parent of a rigid body (rigidbody) should never be scaled

2. Kinematic rigid body (kinematic rigidbody)

A kinematic rigid body (kinematic rigidbody) refers to a rigid body that has the kinematics (is kinematic) option enabled. Kinematic rigid bodies (kinematic rigidbody) are not affected by forces, gravity, or collisions. They are driven by setting the position and rotation of the transform or animating it, and the kinematic rigid body can also interact with other non-kinematic rigid bodies (Non-kinematic rigidbody).

Kinematic rigid bodies (kinematic rigidbody) can awaken them correctly when colliding with other rigid bodies (rigidbody) and apply friction to the rigid bodies (rigidbody) placed on them.

Here are some examples of the use cases for kinematic rigid bodies (kinematic rigidbody):

(1) You want an object to be under physical control, but in other cases it is controlled by script or animation. For example, you can create an animated character whose bones attach a rigid body (rigidbody) attached to the joint (Joint) to use as a ragdoll. Most of the time the character is under animation control, and a kinematic rigid body (kinematic rigidbody) is created. But when you hit it, you want it to become a rag doll and be physically affected. To do this, simply disable the kinematics option, which is to make "is Kinematic" false.

(2) An object that requires an object to push other objects, but not to push itself. For example, if you have an animation platform and you want to place some rigid body (rigidbody) enclosures on it, you should make the platform a kinematic rigid body (kinematic rigidbody) and not just a collider (Collider) without a rigid body (rigidbody).

(3) An object may be required to have an animated kinematic rigid body (kinematic rigidbody), and an available joint (Joint) is used to follow the real rigid body (rigidbody).

3, Static impact components (static Collider)

A static collision component (Collider) is a game object (Gameobject) that has a collision body (Collider) rather than a rigid body (rigidbody). A static collision body (Collider) is used to maintain horizontal geometries that are always in the same position and never move around.

You can add a mesh collision component (mesh Collider) to an existing graphics grid, such as using the import settings (imported Settings) to generate a collision body (Generate colliders), or you can use a different collision component.

You should never move a static collision body Collider by frame, or, as long as you set it as a static collider, it should never move in a scene from start to finish. Doing so will cause the physical engine to re-perform internal computations, which can be costly and significantly degrade performance. Not only that, the behavior of waking other rigid bodies (Rigidbody) based on a static collision body (Collider) is undefined, and moving the static collider (static Collider) does not apply friction to the rigid body (rigidbody) in contact with it.

In summary, a collision body (Collider) that moves in a scene should always be set to a kinematic rigid body (kinematic rigidbody) instead of being set as a static collision body.

"Unity" chapter 11th third-person character controller and collision body

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.