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