Question by
shadrunov · Feb 14, 2017 at 05:54 AM ·
2d-platformerjumping
Jump from the inclined surfaces
I try to add inclined surfaces in my 2d platformer (the tilt of about 30-45 degrees). Character can run on incinclined surfaces well, but I have some troubles with jump from them, because I chek ground using this function:
public bool IsGrounded()
{
if (Math.Abs(MyRigidbody.velocity.y) < 0.1)
{
foreach (Transform ponint in groundPoints)
{
Collider2D[] colliders = Physics2D.OverlapCircleAll (ponint.position, groundRadius, whatIsGround);
for (int i = 0; i < colliders.Length; i++)
if (colliders[i].gameObject != gameObject)
{
return true;//true if we colliding with smthing
}
}
}
return false;
}
So, obviously, when character "slips" or "climbs" on the surface his |velocity| < 0.1 and he is not on the ground already and can't jump. Yes, I can remove this if statement, but in this case I will be able to jump, when ground not only under the character, but on the side of his ground points too.
How can I fix that problem?
Thnx.
Comment