I don’t know if this is a problem with my script or scene ( probably scene ). For the first time in playmode when I press jump button the player jump very high, almost off the screen. Then after that, it goes normally. Here is the script that I am using for jumping.
public static bool reachedEnd;
public float jumpForce;
public static bool isDied;
public static bool canJump;
public GameObject player;
private Collider2D playerCollider;
private Rigidbody2D playerRB;
public Collider2D obstacleCollider;
public Collider2D groundCollider;
void Awake()
{
isDied = false;
playerCollider = player.GetComponent<Collider2D> ();
playerRB = player.GetComponent<Rigidbody2D> ();
}
void Update()
{
if( playerCollider.IsTouching(obstacleCollider))
isDied = true;
}
void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.W) && grounded() && isDied == false)
{
playerRB.AddForce (transform.up * jumpForce,0);
}
print (isDied);
}
bool grounded()
{
bool grounded = false;
if(playerCollider.IsTouching(groundCollider))
{
grounded = true;
}
return grounded;
}