Sorry for my poor English guys
I have some problem with this method.
I tried to make the object jump. But “isGrounded” randomly sets to “true” when groundCheck is not in position of “Ground”-layer objects.
How can I fix this problem?
There is a code from Update:
var ballPos: Vector2 = new Vector2 (ballContainer.transform.position.x, ballContainer.transform.position.y);
var grCheckPos: Vector2 = new Vector2 (groundCheck.position.x, groundCheck.position.y);
isGrounded = Physics2D.Linecast(ballPos, grCheckPos, 1 << LayerMask.NameToLayer("Ground"));
if (isGrounded)
{
Debug.Log("Grounded");
jumpCheck = true;
}
if (!isGrounded)
{
jumpCheck = false;
}