Introduction to Unity Physical systems

Source: Internet
Author: User
Tags creative commons attribution

Unity_ Physical System Brief Introduction

In order to have convincing physical behavior, objects in the game must be accelerated correctly, affected by collisions, gravity and other forces.
There are actually two independent physics engines in unity: one for 3D physics and the other for 2D physics. The main concepts of the two engines are the same (except for the extra dimensions in 3D), but they are implemented using different components. For example, Rigidbody and rigidbody2d.
I recommend reading the Official Unity Handbook

Physical overview Rigidbody (rigid body) Overview

In unity, if you want go to have gravity, collision feedback can occur, it is essential to add a component rigidbody. Since the component replaces its own motion, all should not change position by transform, rotate, instead use forces to push go and let the physics engine calculate the result.
The Rigidbody component has a Is Kinematic property that can be removed from the control of the engine, allowing the motion of the go to be controlled with a script. Note: Try not to use a script to control the switch for this property.

Sleeping

When the speed of a rigid body is much lower than a set minimum linear velocity, the physical engine considers it to be asleep. At this point, go does not move again until it receives a signal. This mode means that the processor does not take the time to update the rigid body state.
You can use WakeUp functions to wake Gameobject.

Colliders (Collider)

The Colliders component defines the shape of an object for physical collisions. It does not need to fully conform to the grid shape of go, in fact, the approximate similarity is more efficient in the game.
The simplest of several collider in Unity: Box Collider, Sphere Collider and Capsule collider;2d Collider: Collider and Circle Collider 2D.
Sometimes it needs to be attached to an object in a combination form, which keeps the processor overhead low and adds some flexibility, but they should have only one rigidbody component on the parent object.
The combination of collider also does not meet our needs, which requires mesh Collider, it can accurately match the object's mesh shape. But do not use it often, it is very high performance requirements. When collision detection is required, it can be set to convex, which is generally used on the geometry.
objects can be individually added to a collider (without a rigid body), but generally the object is static.

Physics materials (physical material)

When objects collide with each other, the surface of the object simulates the properties of the material on it, such as ice cubes, basketball, etc., the friction coefficient of the object, and the elasticity coefficient can be configured with a physical material.

Triggers (Trigger)

The script can be OnCollisionEnter initiated to detect when a collision occurs, or it can be activated by modifying the IS Triggeron the collider to see if collision detection is required. The function of the object script will be called when the collision object passes through when it is started OnTriggerEnter .

Collision function
Is Trigger = falseOnCollisionEnter  //碰撞第一次调用  OnCollisionStay   //保持碰撞中调用  OnColliosionExit  //退出碰撞时调用Is Trigger = trueOnTriggerEnter  //进入触发器OnTriggerStay   //停留触发器OnTriggerExit   //离开触发器
Collision Interaction Static Collision (no rigid body)

Static objects with collider, no rigid body, and not easy to use in the process of the game, will bring you unexpected effects (take up extra performance).

Rigid body Collisions

Objects with collider and rigid bodies can react to the added force from the script;

Kinematic Rigid Body Collisions

Objects with collider and rigid body components open the iskinematic, which can be transformed by transform. It should be used for objects that are occasionally used, such as sliding doors.
You can also switch the Iskinematic property in real time to switch between normal and motion behavior, such as people, generally using animation to control it, this is to use kinematics, and when the explosion, the shattered limbs, can switch to non-kinematics to simulate a better effect.

Joints

You can use a variety of joint components to link two objects, such as one object rotating around another static object. can also do similar to the effect of spring, rope.
Special effects:
When the force applied is greater than this value, a joint break can be set.
The joint can produce a driving force to make it move automatically.

Character Controllers (role Controller)

A collision-based physical feature for a character in a first-person or third-person game. Cannot pass through a static collision object, it can be used to set the speed and direction of the object.

Physics Debug Visualization (Visual Physical Debugging tool)

Visual physical debugging allows you to quickly examine the collision geometry in your scene and analyze common physical scenarios. It provides a visualization of which gameobjects should and should not collide with each other. This is especially useful when there are many colliders in the scene, or when render and collision meshes are out of sync.

打开方式:Windows -->  Physics Visualization

Properties function
Reset Click this button to reset the Physical debugging window to the default settings.
Hide Layers Use the drop-down menu to determine whether to display colliders from the selected layer
Hide Static colliders Select this check box to remove the static collision diagram from the visual file (collision diagram without a rigid component).
Hide Triggers Select this check box to remove the colliders from the visual file that is also the trigger.
Hide rigidbodies Select this check box to remove the Rigidbody component from the visual file.
Hide kinematic Bodies Select this check box to remove a collision body with a kinematic rigid body component (not controlled by the physical engine) from the visual file.
Hide Sleeping Bodies Select this check box to remove the colliders with the Sleeping Rigidbody component (currently not associated with the physical engine) from the visual file.
Collider Types Use these options to remove specific collider types from physical visualizations.
Hide boxcolliders Select this check box to remove the box colliders from the visual file.
Hide spherecolliders Select this check box to remove the Sphere colliders from the visualization.
Hide capsulecolliders Select this check box to remove the capsule colliders from the visual file.
Hide meshcolliders (convex) Select this check box to remove the convex mesh collider from the visualization.
Hide meshcolliders (concave) Select this check box to remove the concave mesh collider from the visualization.
Hide terraincolliders Select this check box to remove the terrain colliders from the visual file.
Hide None Click Hide no clear all filter criteria and display all collider types in the visualization.
Hide All Click Hide all to enable all filters and remove all collider types from the visual file.
Colors Use these settings to define how unity displays physical components in a visualization.
Static colliders Use this color selector to define which color indicates a static collider in the visualization (a collision body without a rigid component).
Triggers Use this color picker to define which color represents the "collision" of "Trigger" in visualizations.
Rigidbodies Use this color picker to define which color represents the Rigidbody component in the visualization
Kinematic bodies Use this color selector to define which color represents the kinematic rigid body component in the visualization (not controlled by the physical engine).
Sleeping bodies Use this color selector to define which color represents the sleeping Rigidbody component in the visualization (not currently associated with the physical engine).
Variation Use the slider to set a value between 0 and 1. This defines how much of the color you choose is blended with the random color. Use it to visually separate the colliders by color and view the structure of the gameobjects
Rendering Use these settings to define how unity renders and displays physical visualizations.
Transparency Use the sliders to set the values to 0 and 1. This defines the transparency of the collision geometry plotted in the visualization.
Force Overdraw Normal rendering geometries can sometimes obscure colliders (for example, the mesh collider plane below the floor). Select the Force overdraw check box to have the visual Renderer Draw collider geometry on the rendered geometry.
View Distance Use this setting to visualize the distance of the view.
Terrain Tiles Max Use this setting to visualize the maximum number of topographic blocks in the

Properties function
Collision Geometry Select this check box to enable collision geometry visualization.
Mouse Select Select this check box to enable mouse hover highlighting and mouse selection. This can be useful if there are large gameobjects blocking each other in the scene.
Summarize

Visual physics Debugging tools are primarily used to analyze and troubleshoot physical activity in the game. Most recommended use:

    • To see active Rigidbodycomponent only: If you want to view only the Rigidbody components that are active and therefore use CPU/GPU resources, tick hide objects with static collisions and hide sleep modes.
    • To see Non-convex mesh collidersonly: a non-convex (triangle-based) mesh collider tends to produce the most contact when its attached rigid body assembly is very close to colliding with another rigid body or colliding object. To display only non-convex mesh object collisions, set the window to display the selected object mode, click the Select None button, and then tick the show meshcolliders (concave) check box.


This work is licensed by Star Meteor Chen using the Creative Commons Attribution-NonCommercial 4.0 International license Agreement.

Introduction to Unity Physical systems

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.