- Home /
Question by
AngryPizzaDev · Sep 30, 2014 at 04:28 AM ·
c#2dcollision
How do I set bounce to set amount
Hello,
I am setting up a falling sprite to bounce off another one using a Physics2D material. It works well, but my problem is right now the amount the sprite bounces is based on how fast it's falling when it hits. I really need to to bounce at a locked velocity (Meaning, when it leaves the object it is bouncing off of, it leaves at the same speed no matter how fast it was going when it hits). Can I do that using the existing physics (as I'd like everything else to work as it is), or do I need to write it out manually based on the collision and just forget the bounce material?
Thanks
Comment
Best Answer
Answer by robertbu · Sep 30, 2014 at 04:59 AM
Untested idea:
void OnCollisionExit2D() {
rigidbody2D.velocity = rigidbody2D.velocity.normalized * someVelocity;
}
Close enough. Had to do it as a new Vector2 in C#, but this worked exactly like I wanted. Thanks.