【PhysX】
1、施加力:
1 if(GUILayout.Button("普通力",GUILayout.Height(50))) 2 { 3 //施加一个力,X轴方向力度为1000,Y轴方向力度为1000 4 addFrceObj.rigidbody.AddForce (1000, 0, 1000); 5 } 6 7 if(GUILayout.Button("位置力",GUILayout.Height(50))) 8 { 9 //施加一个位置力,物体将会朝向这个位置发力移动,力的模式为冲击力。 10 Vector3 force = cubeObj.transform.position - addPosObj.transform.position; 11 addPosObj.rigidbody.AddForceAtPosition(force,addPosObj.transform.position,ForceMode.Impulse); 12 }
2、刚体的碰撞回调:
3、What is Kinematic Rigidbodies?
A Kinematic Rigidbody is a Rigidbody that has the isKinematic option enabled. Kinematic Rigidbodies are not affected by forces, gravity or collisions. They are driven explicitly by setting the position and rotation of the Transform or animating them, yet they can interact with other non-Kinematic Rigidbodies.
Kinematic Rigidbodies correctly wake up other Rigidbodies when they collide with them, and they apply friction to Rigidbodies placed on top of them.
4、What is Static Collider?
A Static Collider is a GameObject that has a Collider but not a Rigidbody. Static Colliders are used for level geometry which always stays at the same place and never moves around. You can add a Mesh Collider to your already existing graphical meshes (even better use the Generate Colliders check box), or you can use one of the other Collider types.
5、The Physics Material is used to adjust friction and bouncing effects of colliding objects.
6、Character Controller
The Character Controller is mainly used for third-person or first-person player control that does not make use of Rigidbody physics.
Character Controller组件用于帮助控制没有RigidBody的组件。
7、Character Controller和RigidBody互斥,同一GameObject只能应用其一。
8、SmoothFollow.js是内置Camera脚本组件,可以让某个Camera紧跟某个对象,实现第三人称Camera。
9、使用Ray检测碰撞
1 //??????0?????? 2 Ray ray = new Ray(Vector3.zero, transform.position); 3 //????????? 4 RaycastHit hit; 5 Physics.Raycast(ray, out hit, 100); 6 //????????????????????????? 7 Debug.DrawLine(ray.origin, hit.point);
10、关节必须依赖于刚体组件。
11、Triger与Collision分布图:
12、动态添加关节组件:
1 if(GUILayout.Button("添加链条关节")) 2 { 3 4 ResetJoint(); 5 jointComponent = gameObject.AddComponent("HingeJoint"); 6 HingeJoint hjoint = (HingeJoint)jointComponent; 7 connectedObj.rigidbody.useGravity = true; 8 hjoint.connectedBody = connectedObj.rigidbody; 9 } 10 11 if(GUILayout.Button("添加固定关节")) 12 { 13 ResetJoint(); 14 jointComponent =gameObject.AddComponent("FixedJoint"); 15 FixedJoint fjoint = (FixedJoint)jointComponent; 16 connectedObj.rigidbody.useGravity = true; 17 fjoint.connectedBody = connectedObj.rigidbody; 18 }