- Home /
Adding bounce when hitting object from below
I'm making a grappling hook and whenever my character grapples and hits the ceiling, he just drags across the ceiling, whilst I would prefer for him to have a slight bounce. I could use a physics material and add bounce, but then he'd bounce if he were to land on the floor as well, which I don't want. If there any way to calculate whether the object being hit is above, and using that changing the bounciness?
Comment
Best Answer
Answer by RVDL_IT · Mar 10, 2019 at 09:57 PM
I fixed it already.
void OnCollisionEnter (Collision other) {
//If the player hits an object above him whilst grappling, they get bounced back.
if(other.contacts[0].point.y > transform.position.y && Grappling == true) {
this.GetComponent<Rigidbody>().AddForce(new Vector3(0, other.relativeVelocity.y * 10, 0));
}
}
Your answer
Follow this Question
Related Questions
Bouncing off Walls in C# 1 Answer
How can I show trajectory of a bouncing ball OnCollisionEnter/OnCollisionExit? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
how to make trampoline in unity 3D 1 Answer