Game Development Reference
In-Depth Information
For more information of each parameter, go to the following link: ht-
tp://docs.unity3d.com/Manual/class-InputManager.html .
The Negative Button and Positive Button here will send the negative and positive value,
which in most cases is used to control directions such as, left, right, up, and down. There
is a Dead parameter, which will set any number that is lower than this parameter to 0 ,
which is very useful when we use a joystick.
Also, setting Type to Key or Mouse Button and enabling the Snap parameter will reset
axis values to zero after it receives opposite inputs.
Physics2D.Raycast
If we take a look at the Grounded() function and check out the following highlighted
code, we will see that we have cast the ray a bit longer than the sprite collider:
if (Physics2D.Raycast (origin, hitDirection, distance,
layerMask.value)) {
_isGrounded = true;
} else if (Physics2D.Raycast (rightOrigin, hitDirection,
distance, layerMask.value)) {
_isGrounded = true;
} else if (Physics2D.Raycast (leftOrigin, hitDirection,
distance, layerMask.value)) {
_isGrounded = true;
}
From the highlighted code, we draw Raycast from the middle of our character down-
ward by 0.58 units. Why don't we set it to 0.5 ? We set it this way to make our character
stay on the edge of the floor surface. If we set it to 0.5 , we will see that the character will
not hit the ground. This is because of the way Box Collider 2D and Polygon Collider 2D
detect other collider objects in Unity, as we can see in the following screenshot:
Search WWH ::




Custom Search