Game Development Reference
In-Depth Information
Physics.Raycast
Why do we need to shit a litle bit from the collider edge by muliple 0.45 instead of 0.5 ?
var hit : RaycastHit;
var v3_hit : Vector3 = transform.TransformDirection (Vector3.
forward) * (f_height * 0.5);
var v3_right : Vector3 = new Vector3(transform.position.x + (collider.
bounds.size.x*0.45), transform.position.y, transform.position.z);
From the line of code if (Physics.Raycast (v3_right, v3_hit, hit, 2.5)) , we
will see that the Raycast is drawing from the middle of our character on the right bound
downward by 2.5 units. Now we can take a look at the Gizmos that we drew in the editor:
As we can see in the preceding figure, our gizmo (the red line) is basically shifting from the
boundary of the box collider (green box) a litle bit. This will only check at the botom of our
character because our box collider covers the line. On the other hand, if we draw the Raycast
at the edge of the box collider, it will cause the problem that our character will be able to walk
on air while the edge of the floor hits the Raycast , as shown in the previous figure.
 
Search WWH ::




Custom Search