Unity 3D physics Manager

As an excellent game development platform, unity 3D integrated development environment provides an excellent management mode, namely physics manager

the physical manager manages the parameters of the physical effects in the project, such as the gravity, rebound force, velocity and angular velocity of the object

in unity 3D, execute the command edit → project settings → physics to open the physical manager, as shown in the figure below

you can change the physical effects in the game by adjusting the parameters in the physical manager as needed, as shown in the table below

parameters meaning

function
Gravity Gravity It is applied to all rigid bodies and works only on the y-axis
Default Material Default physical material If a collider does not have a physical material set, the default material is used
Bounce Threshold Rebound threshold If the relative velocity of the two colliders is lower than this value, they will not rebound
Sleep Velocity Dormancy speed Objects below this speed will go into sleep
Sleep Angular Velocity Sleep angular velocity Objects below this angular velocity will go into sleep
Max Angular Velocity Maximum angular velocity It is used to limit the angular velocity of rigid body and avoid numerical instability during rotation
Min Penetration For Penalty Minimum penetration How far can two objects penetrate before the collision detector separates them
Solver Iteration Count Iterations It determines the calculation accuracy of joints and connections
Raycasts Hit Triggers X-ray detection hit trigger If this function is enabled, a hit message will be returned when hit collision occurs during ray detection; If this feature is turned off, no hit message is returned
Layer Collision Matrix Layer collision matrix Define the behavior of layer collision detection system

comprehensive case: maze

case conception

Maze game is a common game type, players in a limited time, looking for treasure box in the maze, so as to achieve the purpose of customs clearance

the purpose of this project is to search for the hidden treasure box in the maze through virtual roaming in the scene, and collect it when close to the treasure box, so as to realize the collision detection function

case design

This case creates a three-dimensional maze scene in unity 3D. There are several treasure boxes scattered in the scene. The game player needs to find the treasure box within the specified time, approach and collect it, and finally pass the customs

project implementation

1) set up maze scene

Step 1): create a new project and name the scene MIG

Step 2): create a game object. Execute the GameObject → 3D object → plane command in the menu bar to create a plane and assign a material to it

execute the GameObject → 3D object → cube command to create several boxes to form a maze scene, as shown in the following figure

Step 3): import model resources. Select the 3D model resource from unity 3D store and load it into the scene, and name it as treasure, as shown in the figure below

Step 4): import the model resources into the hierarchy view, as shown in the following figure

Step 5): execute the commands assets → import package → custom package to add first person resources, as shown in the figure below

Step 6): select the first person resource and click Import to import it, as shown in the figure below

Step 7): search for the first person controller in the project view, add it to the hierarchy view, and place it in an appropriate position on the plane, as shown in the following figure

Step 8): because the first person resource has its own camera, it is necessary to turn off the camera in the scene

2) add trigger

Step 9): select tree, add box Collider to the tree object, and check the is trigger attribute, as shown in the following figure

Step 10): write the script triggers.cs, and the code is as follows

usingUnityEngine;usingSystem.Collections;publicclassTriggers:MonoBehaviour{voidOnTriggerEnter(Colliderother){if(other.tag=="Pickup"){Destroy(other.gameObject);}}}

Step 11): link the triggers script to the first person controller

Step 12): add a label pickup to the tree

3) add counting function

Step 13): modify the script

usingUnityEngine;usingSystem.Collections;publicclassTriggers:MonoBehaviour{publicstaticinttemp_Num=0;voidOnTriggerEnter(Colliderother){if(other.tag=="Pickup"){temp_Num++;Destroy(other.gameObject);}}voidOnGUI(){if(temp_Num==5)if(GUI.Button(newRect(Screen.width/2f,Screen.height/2f,100,50),"playagain")){temp_Num=0;Application.LoadLevel("migong");}}}

Step 14): add the scene to the build settings, as shown in the following figure

4) add timing function

Step 15): complete the code as follows

usingUnityEngine;usingSystem.Collections;publicclassTriggers:MonoBehaviour{publicstaticinttemp_Num=0;publicintparachuteNum;inttimer;inttime_T;boolisWin=false;boolisLose=false;voidStart(){Time.timeScale=1;GameObject[]objs=GameObject.FindGameObjectsWithTag("Pickup");parachuteNum=objs.Length;time_T=(int)Time.time;}voidUpdate(){timer=20-(int)Time.time+time_T;if(temp_Num==parachuteNum&&timer!=0){isWin=true;}if(timer==0&&temp_Num!=parachuteNum){isLose=true;}}voidOnTriggerEnter(Colliderother){if(other.tag=="Pickup"){temp_Num++;Destroy(other.gameObject);}}voidOnGUI(){GUI.Label(newRect(0,0,100,50),timer.ToString());if(isWin==true||isLose==true){Time.timeScale=0;if(GUI.Button(newRect(Screen.width/2f,Screen.height/2f,100,50),"playagain")){isWin=false;isLose=false;temp_Num=0;Application.LoadLevel("migong");}}}}

Step 16): Single Play according to 38062; " Test, results as shown in the following map.

Similar Posts: