Unity3d Physical Rigidbody Prevention interspersed
@ Guangzhou Dragon
Unity's physics engine uses the PhysX engine, and the components inside it are rigidbody! that can simulate physical effects!
Rigidbody, this is can be interspersed, if interspersed with more words, there will be unpredictable control!
But Rigidbody has a problem, that is, when interspersed, how to react, in fact, we can use the ray to pre-test!
This is what we are talking about today Physics.raycast to make a pre-judgment!
static bool Raycast (Vector3 origin, Vector3 direction, float distance = mathf.infinity, int layermask = defaultraycastlayers);
This is a static function, belongs to the physics class, Origin is the starting point, direction is the direction, it can be said to be the length, distance is the distance length, Layermask is the layer!
Code: Vector3 fwd = transform. Transformdirection (Vector3.forward);//value in current direction fwd
if (Physics.raycast (Transform.position, Fwd, 10))//If this ray has touched this object, pause it so that it can be prevented from interspersed!
Print ("There is something in front of the object!");
I want to use the code to simulate the actual physical effects!
By animating the animation in the bone, and testing it, then simulating the addforce so that another rigidbody can be physically processed!
Especially in the non-human control problem, Unity3d does not give a certain component to deal with, which requires us to simulate, is the object of the skeletal animation, binding on the bones of the Ray
The code of the detection, at the point of the collision, give another object a force, so that can be effectively interspersed processing!
You are welcome to Exchange qq:1357098586 with me.