- Home /
Question by
afsalontai · Feb 11 at 03:45 PM ·
velocityrigidbody.addforce
Bounce Mechanic for Doodle Jump,
I am currently working on a Doodle jump project. I am having problems with the bouncing mechanic where I need the player to bounce of the platforms at a constant height; however, this is currently not work does anyone know why? The player just falls to the platform and nothing happens.
Here is the script I am using:
public float jumpForce = 10f;
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.relativeVelocity.y <= 0f)
{
Rigidbody2D rb = collision.collider.GetComponent<Rigidbody2D>();
if (rb != null)
{
Vector2 velocity = rb.velocity;
velocity.y = jumpForce;
rb.velocity = velocity;
}
}
}
},I am currently working on a Doodle jump project. I am having problems with the bouncing mechanic where I need the player to bounce of the platforms at a constant height; however, this is currently not work does anyone know why? The player just falls to the platform and nothing happens.
Here is the script I am using:
public float jumpForce = 10f;
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.relativeVelocity.y <= 0f)
{
Rigidbody2D rb = collision.collider.GetComponent<Rigidbody2D>();
if (rb != null)
{
Vector2 velocity = rb.velocity;
velocity.y = jumpForce;
rb.velocity = velocity;
}
}
}
}
Comment