unity2d issue with linecasts.

Hello I am having a problem where the linecast will only detect a collision to a floor in the middle of the object but in my game there are mutliple floating objects and to get the optimin jump you need to jump at the end of the block. This is described in the picture below.

my code for this is:

    private Transform groundDetector;
        void Awake()
    		groundDetector = transform.Find("GroundCheck");
    void Update()
        	grounded = Physics2D.Linecast(transform.position, groundDetector.position, 1 << LayerMask.NameToLayer("Terrain"));  
if (grounded) {
			doubleJump = false;
		if ((grounded || !doubleJump) && jump) {
            // Add a vertical force to the player.
            anim.SetBool("Ground", false);

			rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 0);

            rigidbody2D.AddForce(new Vector2(0f, jumpForce));

			if(!grounded && !doubleJump){
				doubleJump = true;


for some reason the jump actually works but after the mid-point thedouble jump does not work


A simple way is to create 3 small boxes which will all fire a Linecast : one on the middle, one on the left and one on the right of the player, then you’ll have to check if all hits are null in order to avoid your problem.

A second solution is to use the OverlapArea

With your current script a third solution will be to create 3 ground detectors and do a LineCast to each of them. You can find an example here