private void Update() { if (canJump) { GetComponent <Rigidbody2D>().velocity = jumper.GetMovement(); //Jump! if (updatePlayerPosition) { //Where do we jump now to get to the target? jumperModifier = (transform.position.x > enemyEngine.GetTargetPosition().x) ? 1 : -1; RotateToTarget(); updatePlayerPosition = false; StartCoroutine(SetTargetPositionAfterSeconds()); } GetComponent <Rigidbody2D>().velocity += bullet.GetMovement() * jumperModifier; //Move towards target canJump = false; //We shall not jump until next timer states so } else { if (Time.time - lastJumpTimer > jumpDelay) { //Cast a 2-width box into the ground. The box is so that the entity doesn´t get stuck in platform´s edges //((which used to happen and was pretty annoying)) EnemyEngine enemyEngine = GetComponent <EnemyEngine>(); List <RaycastHit2D> groundRay = new List <RaycastHit2D>(); ContactFilter2D contactFilter2D = new ContactFilter2D(); int groundRayCount = Physics2D.BoxCast(groundPoint.transform.position, new Vector2(2, groundCheckRadius), 0f, Vector2.down, contactFilter2D, groundRay, groundCheckRadius); int i = 0; bool stop = false; while (i < groundRayCount && !stop) { if (groundRay[i].collider.gameObject.layer == enemyEngine.GetGroundLayer()) { canJump = true; lastJumpTimer = Time.time; stop = true; } i++; } } } }